I've a react native component which has multiple buttons in it, each button is a choice and user can have one or multiple choices (more about the idea in the image below). What I need here is `onClick` on of any of the buttons inside the component I wanna take those choices and store them somewhere else.

The problem is when I press on a button it doesn't gets saved immediately it just logs the previous value how can I return the onChange prop with the updated value.

snack working demo: <https://snack.expo.io/OXhu3r-SX>

here is my component:

Note: removed styling for better readability

```
const InputButton = ({ defaultValue = null, isMultiple, onChange, options, styled, alwaysGreen }) => {
  const initValue = isMultiple ? defaultValue || [] : defaultValue;
  const [value, setValue] = useState(initValue);

  const updateValue = (option) => {
    if (isMultiple) {
      // onClick if option is not inclded in the array **add it** otherwise **remove it**
      !value.includes(option) ? setValue([...value, option]) : setValue(value.filter((v) => v !== option))
    } else {
      setValue(option);
    }
    onChange(value)
  };

console.log("if I log the value here it's good to go and updated, updated value is >", value)

  return (
    <View>
      {options &&
        options.map((option, i) => (
          <TouchableOpacity key={`${i}`} onPress={() => updateValue(option)}>
            <Text>
              {option}
            </Text>
          </TouchableOpacity>
        ))}
    </View>
  );
};

export default InputButton;

```

[![Here is the Idea](https://i.stack.imgur.com/s1UlB.png)](https://i.stack.imgur.com/s1UlB.png)