Reputation: 139
Hi i am trying to work on a app, which has some predefined code of redux, and react. I am trying to get the players data which is formated json file and pass it to useSate hook.
The data which I get using
const players = useSelector(getPlayers); // redux
looks perfect when I do console log, however when I pass this to useState
const [playerData, setPlayerData] = useState(players); //react
there is no data on the console.
I do not know if this is the right way to do, if not what would be the best solution to this? as I am more into react hooks and not redux.
any help is appreciated . Thanks
Upvotes: 0
Views: 1285
Reputation: 697
you can set it in useEffect
like that but my suggestion is to use the directly redux players
variable.
useEffect(() => {
setPlayerData(players);
}, [players])
Upvotes: 1