Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

redux cannot read properties state) => state.useSelector

useEffect(() => {
    // fetch user data when component mounts
    dispatch(loadUser(tokenRecognized)); 
}, []);

useEffect(() => {
    // check if user has been fetched (will not be the case on mount)
    if (auth.user) {
        axios
        .get(`/api/items/item/${auth.user._id}`)
        .then(res => {
            return res.data;
        })
        .then(json => {
            setFavArray(json);
        })
        .catch(err => console.log(err));
    }
}, [auth.user]); // perform this when `auth.user` changes
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #redux #read #properties
ADD COMMENT
Topic
Name
7+3 =