I have a react-native app that has boolean values to render certain components but the state is not updating in useCallback
export const Foo = <T>(props):<T> => {
const value = undefined
const [bar, setBar] = useState<boolean>(false)
useEffect(() => {
pipe(
value,
O.fromNullable,
O.fold(
() => setBar(false),
() => setBar(true)
),
)
}, [value])
const foo = useCallback(() => {
runFirstFunction() //changes some of the states
pipe(
bar,
B.fold(
() => falseFunction(),
() => trueFunction(),
),
)
restOfFooFunctionality()...
},[setBar])
}
foo is getting called as the onPress function for a component, when foo is called the state value gets a value and the useEffect takes effect and bar has the value of true but foo initially has the state of bar where it is false and nothing in foo will make it rerender to update the state I am looking for a way to get the current state of bar inside useCallback() to call the functions inside of useCallback()
I have tried playing around with the dependencies but that just broke the app and calling setState doesnt update the state inside useCallback(), hope someone has and awesome solution fr this dont want to redo the entire file