Home > other >  Submit button not giving required result
Submit button not giving required result

Time:07-18

My submit button is not displaying output when i am pressing it but when i do a backspace it is giving me the output on the screen. enter image description here

CodePudding user response:

Post code instead of posting images

According to the image that you have provided, inside saveTask you are pushing the obj to the taskList and then passing it to the state updating function. Arrays are of reference type and since here you are not passing a new array, react will figure out that the array hasn't changed (although you have appended the obj) and hence it won't trigger a re-render.

So change your code to this,

const saveTask = (taskObj) => {
      setTaskList(prevList => {
           prevList.push(taskObj) 
           return [...prevList]      
      })
}
  • Related