Home > Software design >  react native im trying to change the state of a button but its taking only the ternary else side
react native im trying to change the state of a button but its taking only the ternary else side

Time:03-09

im trying to change the state using this but everyTime it takes add function only how to make the state change onPress ..what can i do please let me know

component //

        <Searchitems
          key={index}
          crypto={crypto}
          multipletest={multipletest}
          remove={crypto => remove(crypto)}
          add={crypto => add(crypto)}
          // status={status}
          removes="Remove"
          adds="Add"
           />




const [statusss, setStatus] = React.useState(false);   
onPress={() =>
          setStatus(!statusss) ?  props.remove(crypto)  :  props.add(crypto) 
        }

CodePudding user response:

As mentioned in my comment, it is a bit difficult to understand what you are trying to do with your code. But still, try it like this. It appears that you are trying to check condition on a function.

const [statusss, setStatus] = React.useState(false);

useEffect(() => {
  statusss ? props.remove(crypto)  :  props.add(crypto)
}, [statusss]);

<SomeComponent
  onPress={() => setStatus(!statusss)}
/>
  • Related