Validation retriggers when component is mounted again.
See original GitHub issueBug report
Suppose I need to fetch data with a POST request, where I have to send the ids in the request body.
const MyComponent = (props) => {
const body = useMemo( () => ({ ids: props.ids }), [])
const { data } = useSWR(['/api', body])
return //...
}
This works fine, the problem is that when I go to another page and then get back to the first one (containing MyComponent) the request is retriggered. This makes sense since useMemo only caches the data as long as the component is mounted. But is there a way to avoid retriggering the request when mounting the component again?
Thanks in advance,
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Can't perform a React state update on an unmounted ...
It stops the repetitive call of setState method because it validate _isMounted value before setState call, then at last again reset to false ......
Read more >React - How to Check if a Component is Mounted or Unmounted
This is a quick post to show how to track the mounted status of a React component so you can check if it's...
Read more >useForm - trigger - Simple React forms validation
Manually triggers form or input validation. This method is also useful when you have dependant validation (input validation depends on another input's ...
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
If you do not include an array of triggers, it will run after every render. Open RiverInformation.js : nano src/components/RiverInformation/ ...
Read more >Validation Observer - VeeValidate
Here is a small example, again with Vuetify components wrapped by the Provider's withValidation ... A method that triggers validation for all providers....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
with
revalidateOnMount: false
swr doesn’t make request even when there is no cached data yet. withrevalidateOnMount: true
request will be send even if cached date exists. I think optionrevalidateOnCacheExists: false
(or something like this) will be useful when we need to display cached date without any data requests.What’s the reason for not fetching data if it doesn’t exist in cache when we set
revalidateOnMount: false
?