Category : setstate

In React Docs, handling events article: how state is being updated to the opposite boolean value, I have a question. Why do we need to add .isToggleOn after isToggleOn: !prevState Why can’t I just simply write isToggleOn: !prevState? prevState is {isToggleOn: true}. So !prevState should be {isToggleOn: false}. Am I right? It confuses me, because ..

Read more

I have a hover state that changes div background color and adds a <p> tag to a mapped component: const [isHover, setIsHover] = useState(false) Here is the mapped component where I set the state: const AddSectionButton = ({ isHover, setIsHover, sections, setSections, nextSectionId, setNextSectionId, sectionTitle, setSectionTitle, sectionId, }) => { return ( <AddSectionDiv onMouseEnter={() => ..

Read more

I have this useState statement: const [userLogged, setUserLogged] = useState(); And this is a fragment of my code in a custom hook: await axios.post(‘http://localhost:3000/users/register’, form).then( (res)=> { setUserLogged(res.config.data) console.log(UserLogged) window.location.href = "http://localhost:3001/" }); When my callback is working, i want to set the state of userLogged using setUserLogged with the user object from res, but ..

Read more

I am having websocket connection between client and server. Client want to display list of ID’s and its progressValue. Server on other end is sending always array of obj with length 1 for example [{"processid": "1","progressVal" : 10%}] [{"processid": "2","progressVal" : 5%}] [{"processid": "1","progressVal" : 25%}] [{"processid": "3","progressVal" : 1%}] [{"processid": "2","progressVal" : 12%}] like ..

Read more