Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get params in react hooks component?

For class component there is "this.props.route.params" option. How to get params from one screen to other screen in react hook functional component.

"react": "16.11.0",
"react-native": "0.62.2",
"react-navigation": "@react-navigation/native": "^5.1.2",
like image 671
Rahul Bhogayata Avatar asked Nov 02 '25 11:11

Rahul Bhogayata


1 Answers

You can use the hook useRouter from @react-navigation/native

import * as React from 'react';
import { Text } from 'react-native';
import { useRoute } from '@react-navigation/native';

function MyText() {
  const route = useRoute();

  return <Text>{route.params.caption}</Text>;
}
like image 141
Jackmekiss Avatar answered Nov 04 '25 10:11

Jackmekiss