简体   繁体   中英

useEffect unable to run in react native

I am using redux in react native, When the state of redux changes, useEffect is not executed, here is my code


const message = useSelector(state => {
    const { privateChat } = state
    const chatObj = privateChat.filter(s => s.user === replyer) // chatObj is an object
    console.log('changed')
    return chatObj[0]
  })
  useEffect(() => {
    console.log('message1', message)
   
  }, [message])

every time the 'changed' was printed, useEffect did not print out the data,I dont konw what went wrong

This might help

const privateChat = useSelector(state => state.privateChat);

const chatObj = privateChat.filter(s => s.user === replyer) // chatObj is an object
console.log('changed');

useEffect(() => { 
   console.log('message1', chatObj) 
}, [privateChat]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM