Search code examples
reactjsreduxreact-reduxredux-sagause-state

trying to set the default value of useState with useSelector but it doesn't work


I was trying to get my state with useSelector and when I console.log it I get my data perfectly but when I try to put that data in useState my value stays empty this is my code :

const settings = useSelector((state) => state.getsettings);
console.log("SETTINGS ==>", settings.info);``
const [getValue, setValue] = useState(settings.info.fulfilmentAutoma);

my "getValue" is empty while my "settings.info.fulfilmentAuto" is not!

enter image description here

any help please ?!


Solution

  • you should use useEffect:

    useEffect(()=>{
     setValue(settings.info.fulfilmentAutoma);
    });