I’m starting to use react native and trying to pass a setState function from one screen to another using the expo routing:
...
const [message, setMessage] = useState(null);
...
<Pressable
onPress={() =>
router.push({
pathname: "/page2",
params: {message: message, method: setMessage},
})
}
...
however when I go to use the function in page2, i get the error message:
method is not a function (it is ‘function bound dispatchSetState(a0) { [bytecode]}’)
anyone know how i can pass functions between screens in react native???
alternatively how do you go about changing the state in a homescreen from a screen further down the stack.
All help and advice is greatly appreciated! 🙂
I tried passing the function in to the params object like a variable but got an error
euanbagguley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.