In React js I would pass setState like below from parent components to child components, however in React Native setABC is undefined. What's the best way to achieve the below in React Native?
Parent.js:
function Parent(){
const [ABC, setABC] = useState();
return(
<routes>
<route path="/child" element={<Child setABC={setABC} />} />
</routes>
);
}
export default Parent;
Child.js:
function Child({setABC}){
let doSomeStuff = () =>{
setABC("ABC");
}
}
export default Child;
the problem is not related to react-native
you passed the prop as setState in parent.js
<Child setState={setABC} />
and received it as setABC function Child({setABC}){
it should be like this
function Child({setState}) {
...
}
or change the prop name in Parent.js to match Chlid.js
<route path="/child" element={<Child setABC={setABC} />} />