Click here to Skip to main content
14,733,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//I try to write tic toc toe with react-redux,but my code in the vscode is not work.
//this message in terminal:

React Hook useEffect contains a call to 'setuser'. Without a list of dependencies,
this can lead to an infinite chain of updates.
To fix this, pass [props.xisNext] as a second argument to the useEffect Hook

What I have tried:

function Square(props){
    const [user,setuser]=useState(props.xisNext);
    function handleclick(){
      props.addPerson(props.id)
    }
    useEffect(()=>{
      setuser(props.xisNext)  
    })
  return(
    <button 
      onClick={handleclick}
    >{user[props.id]} 
    </button>
  )
}
Posted
Updated 9-Nov-20 18:25pm
v3

1 solution

Have a look at the documentation: https://reactjs.org/docs/hooks-reference.html#conditionally-firing-an-effect[^]

Thus pass it like:
useEffect(() => {
    setuser(props.xisNext)
  },
  [props.xisNext]
);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900