I'm trying to extract data from state. I'm using redux.
const {currentPost } = useSelector(state => state.posts)
I expected to get an object with properties. Instead I get couple of undefined and then I get an object.
These undefined on the start causes that I can't destructure further like const {currentPost: {id} } = useSelector(state => state.posts)
and returns error that it can't read property of undefined.
These posts are obtained by API.
I've tried to workaround it by use a function which checks if this currentPost
is undefined and then pass null into these properties. However it's not suitable for project and this solution is error prone.