Can't set default useState to incoming redux data

Viewed 38

I need to set state with the default value from a redux reducer. I can console.log the value just fine, I'm guessing its not "fast" enough?

I tried setting a variable to the reducer value I need then calling useState with the variable but that didnt work either...

const ChatProvider = ({ children }) => {
  
  const conversations = useSelector((state) => state.conversations) // all conversations

  
  const [activeConversationId, setActiveConversationId] = useState(conversations[1]?.conversationSid)
  console.log(conversations[1]?.conversationSid) // I get my string "Ox990"
  console.log(activeConversationId) // I get undefined...

// render stuff here

}
0 Answers
Related