score:0
you can use getDerivedStateFromProps and pass an empty parameter while you navigate, that triggers the method once after the navigation.
// caller
this.props.navigation.navigate('SOMEWHERE', {})
// SOMEWHERE
static getDerivedStateFromProps(nextProps, prevState){
doSomething()
return null
}
score:0
You could set a variable in localStorage when you first load your page. Then, whenever you render, you simply get and test that variable:
async componentDidMount() {
...
if(localStorage.getItem('reRender') !== "true") {
//Processing to do only for the very first render
localStorage.setItem('reRender', "true");
}
}
You could reset the variable depending on your use case afterwards (for example when logging out):
localStorage.removeItem('reRender');
score:4
componentWillMount()
gets called pre-render and only once until the page refreshes.
https://facebook.github.io/react/docs/react-component.html#componentwillmount
componentDidMount()
gets called immediately after render() and the DOM is available at this time. This will happen only the first time it's loaded until the page refreshes.
https://facebook.github.io/react/docs/react-component.html#componentdidmount
Source: stackoverflow.com
Related Query
- ReactJS: How to make a component call a method only the very first it is rendered?
- How to make the first option unselected while the component is rendered in select with multiple?
- ReactJS how to render a component only when scroll down and reach it on the page?
- How to make a second API call based on the first response?
- How to properly make a GET call in React returning an observable (resembling the method in Angular and not using promises)?
- React: How can I call a method only once in the lifecycle of a component, as soon as data.loading is false
- React useEffect calls API too many time, How can I limit the API call to only once when my component renders?
- How can I use useEffect in React to run some code only when the component first mounts, and some other code whenever an event occurs (repeatedly)?
- How to make an http call in parent component to setState and then send the state to all child components?
- How to make useEffect hook call the provided effect only if all the elements in inputs change?
- How to reload the Data of a child when a child Component is being rendered in ReactJs
- How to call method in child component only once after parent state update
- Call a method from another Component after the Async function reactjs
- How to call the method inside the function (Clicking the a href to logout) using ReactJS
- How to handle desktop vs mobile layout for a component when the mobile design is VERY different (aka cannot make use of grid layout)?
- How to access the method of other Function component functionality in different component in ReactJS
- How to make only one button disabled on click in map method and how to change className after the timer expires in React?
- I'm using router for the first time.. How can I make route to render first component automatically when it's opened?
- How do I make a component to render only when API call is completed?
- How to call method inside main Component from outside in Reactjs
- How to access method of the child component from parent in reactjs
- CSS- how to make one component move to the left only if there are new components shown on the right
- React onClick method sets variable to true but only for a second when the page reloads - how to make changes permanent?
- how to make reactjs call Component from external file
- How to make webpack bundle my assets/image/ although i call them from a url, into the component
- React Error – Each child in a list should have a unique “key” prop only on the first component rendered
- How to make two Get requests, the second one can only be made after the return of the first one?
- How do I make a React prop only required when used in the context of a Container component with Typescript?
- How to make my ant design Header name dynamic according to the content component rendered
- How to make React page render only change component instead of the whole page?
More Query from same tag
- change icon tag with javascript
- Too many re-renders. React limits the number of renders to prevent an infinite loop.?
- Updater function syntax with React setState
- React - what is the proper way to do global state?
- Promise { <state>: "pending" } - Should we use .then after async / await? Confused
- how to avoid repeating similiar onclick events in react
- How do I paginate data in ReactJs?
- Docker: EACCES: permission denied, mkdir '/app/node_modules/.cache'
- Cannot read property 'checked' of undefined react checbox
- Why is .then() undefined in redux promise?
- Material UI Switch toggle has bugs and doesn't change properly
- If React props are readonly, how they can change (whats the usage of getDerivedStateFromProps)?
- React-MaterialUI: Horizontally aligning single tab to right and others to left in App Bar ->Tabs -> Tab
- How to get a date value from a DatePicker in React
- Is there a secure way to use React.js with a Python Flask backend for a multi-user, password protected site
- React.js: Combining properties from an Array of Objects
- Removing references to Gatsby
- Conditional logic jsx react
- React State seems to be overwritten / setState seems not to work
- react-router-dom useParams() inside class component
- VisualStudio Code marks error in React code to close html tag
- Using Grid with SortableJS
- React - State is defined in one parent function, but not in the other parent function being called from the child
- Test React component (Jest & Enzyme) that renders differently after Ajax
- Infow window onclick is not working
- socket.io-client + react, where to connect to the server?
- React Hook "useContext" cannot be called in a class component
- Why is react-single-page-navigation only working in Components without constructor and state?
- Overlay text for OfficeUI fabric PivotItem
- Why does the 'useState' hook invoke the initial state when it's a function reference?