I’m a beginner at react native. I wanted to pass data from login.js to home.js based on the user logged in. But when i tried to use the code below, the error “cannot read property ‘tasks’ of undefined when entering home.js. i’ve checked with console.log in login.js, it shows up. I have no idea how to pass it to home.js.
Login.js
const Login = () => {
const navigation = useNavigation();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleLogin = () => {
axios
.post('http://192.168.1.10:3000/users/login', {
email,
password,
})
.then(res => {
console.log(res.data.metadata);
console.log(res.data.tasks);
navigation.navigate('Home', {tasks: res.data.tasks});
})
.catch(err => {
console.log(err);
});
};
Home.js
const Home = ({route}) => {
const tasks = route.params.tasks;
console.log(tasks);
I am expecting the res.data.tasks to be able to be passed from login.js to home.js. But it can’t read the property ‘tasks’ and shows up ‘undefined’
Romeo Kurniawan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.