score:1
You can use navigation.replace
Use
this.props.navigation.replace('Sc2');
Instead of
this.props.navigation.navigate('Sc2', {username: this.state.username});
You can find more from here https://reactnavigation.org/docs/en/navigation-key.html
score:1
Use this instead of navigation.replace
navigation.reset({
index: 0,
routes: [{ name: 'Profile' }],
});
score:1
"Replace" is only available in stack navigation
replace typed:
import { useNavigation } from '@react-navigation/core'
import { StackNavigationProp } from '@react-navigation/stack'
type YourNavigatorParamList = {
CurrentScreen: undefined
DifferentScreen: { username: string }
}
const navigation = useNavigation<StackNavigationProp<YourNavigatorParamList, 'CurrentScreen'>>()
navigation.replace('DifferentScreen', { username: 'user01' })
https://reactnavigation.org/docs/navigation-prop/#navigator-dependent-functions https://reactnavigation.org/docs/typescript#annotating-usenavigation
score:6
Incase anyone's still figuring out how to replace screens in React Native and is using react-navigation
, here it is:
import { StackActions } from '@react-navigation/native';
navigation.dispatch(
StackActions.replace('Profile', {
user: 'jane',
})
);
For more information refer: https://reactnavigation.org/docs/stack-actions/#replace
Source: stackoverflow.com
Related Query
- How can I replace screen with React Navigation for React Native
- In React Native how can I test my components with Shallow Rendering?
- How can I search for a component with specific key in React Developer Tools?
- How do I pass a Prop to a Navigation Screen Component - React Native
- React Native start failed with error code -4094 how to solve this ONCE for ALL?
- ReactJS - How can I implement pagination for react with keep state when route change?
- How can ı pass function with state for react useContext
- How to apply react-native-linear-gradient for the entire app background with React Native
- React Native - how can I pass a function to a stack screen in a navigator?
- How can I uglify my bundle files for React with gulp?
- How can I replace Markdown-rendered HTML tags with React components?
- How can I add multiple path for home page with react router dom 6?
- How can I use create-react-app for React version 16.x.x with TypeScript?
- How can I replace bits or string with React component, react-router-dom Link or an anchor tag <a></a>
- How can i set onchange in a map with React for Switch Buttons from React-Bootstrap?
- React - How can I parse large JSON objects for graphing. Struggling to do so with State
- How to implement React App navigation for VSCode extension with webview
- React useState: How can I update my useState with onChange for input and OnClick for the button?
- How can I create multiple instances of a React component (having an infinite animation) with different values for the :root variables
- How can I use react router in nested page with "exact paramater" for my this scenario?
- How can I define a background image to fill the screen and remove edges on the left and right in React with Material UI?
- How can I write an adapter for my React Final Form component with Typescript?
- How can I show sorting icons all the time and with blue color for current sorting column in react material-table
- How to Improve performance for React Native geolocation running screen
- How can I test a button which uses props.history for it's onClick with react testing library?
- how to pass products id with redux count in react native for ecommerce like addtocart function
- How can I use multiple refs for an array of elements with hooks?
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- react Material-ui, How do I know I can use onClick for button?
- How to test style for a React component attribute with Enzyme
More Query from same tag
- Prevent React/Redux Datatables initializing before data is available
- Show hide toggle List Component AntDesign
- Reactjs mapping to objects in Array
- React & TypeScript: Avoid context default value
- React Hooks useEffect saves the last state and won't update it with the new one. It runs twice with two different states
- React render parent from child
- Dynamic Form in React with Redux-Form
- How to resolve this error? I cant install this (@ramonak/react-excel) package for edit Imported Excel
- React: How can I get the closest number in tens, hundreds, thousands... of a given number?
- how is it possible to use flowtype to define a prop in react context of a component?
- $el.find(...).iCheck is not a function
- React: How to logout users when refresh token is expired while automatically logging in those that aren't yet
- React refs - accessing DOM nodes using refs
- Boolean params in Axios get request automatically getting converted to string in server side
- Do I need to use PrevState even if I spread the state into a variable?
- Change a tag to Link in react-bootstrap dropdown
- How to access useEffect's async data in another function within a component in React
- React component taking some random values
- ReactJS onclick toggle class event multiple times
- Figuring out how to mock the window size changing for a react component test
- JSreact render issue
- Updating state with React
- Can't call class functions from main, "is not a function" error
- Could the Delete modal be getting hijacked by React-Router?
- React dynamic components from JSON object
- React.memo 2nd Parameter Dependency Function Not Working as Expected
- How can we get pass data from child to parent in reactJS?
- React native: how to split backgroundColor of circular View into 2 different colors?
- Bind controls with elements of sibling component
- MUI responsive Tabs