score:3
Accepted answer
Right now your useEffect
is run on every render since it doesn't have any dependencies supplied as a second argument. The other issue is skipping the effect on first render.
If the initial value for the tile contents marker is null then you can solve this with something like:
useEffect(() => {
// exit early if the Tile contents are the initial content values
// which means the animation shouldn't run
if (props.contents.marker === null) {
return;
}
value.setValue(0);
Animated.timing(value, {
toValue: 100,
duration: 10000,
useNativeDriver: true
}).start();
// note the addition of the dependency array here so this effect only runs
// when props.contents.marker changes
}, [props.contents.marker]);
See https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects for more info on the second argument to useEffect
.
Source: stackoverflow.com
Related Query
- How to fix React-Native animation to only animate "this" component
- Invalid hook call. Hooks can only be called inside... how to fix this maintaining the react class component
- How do I fix "Cannot assign to read only property 'style' of object" in this React component?
- How to render component only once in React Native
- how do I fix this ant design datepicker component in my react project .I have shared a screenshot
- How can I animate a react.js component onclick and detect the end of the animation
- Adding border only to the one side of the <Text/> component in React Native (iOS)
- How in React native destroy an component instance to avoid memory leak and release underlie views objects of native code?
- How to import component in react native past two folders?
- How to trigger a CSS animation on EVERY TIME a react component re-renders
- How to reuse the React JS component in React Native
- How to fix React Router component not updating as route changes
- React Native - LayoutAnimation: how to make it just animate object inside component, not whole component/view?
- react native how to check if Component current show in screen
- How do I pass a Prop to a Navigation Screen Component - React Native
- How to make a React component fade in on scroll using IntersectionObserver, but only once?
- React Native start failed with error code -4094 how to solve this ONCE for ALL?
- How to fix React Native error "jest-haste-map: Haste module naming collision"?
- React Native - Jest: Broken since update to 0.56. How to fix it?
- React only binds Component methods to this - work around?
- How to ensure a constant inside a component is only calculated once on start in React (Native) with hooks?
- How to use React Native Animate to change view flex from 0 to 1
- How to properly update a react native swiper component when state changes?
- How to fix Error: useHref() may be used only in the context of a <Router> component
- How to animate a React component on render?
- how to apply gradient animation effects in react component
- How could I structure this React Native Section List implementation
- How to add new props dynamically to the component using navigator in React Native
- How To Add More component dynamically React Native
- How to split a component when it gets big. ReactJs or React Native
More Query from same tag
- Redux managing arrays of objects and finding nested objects
- How to connect component in html props in react-tippy to redux form
- Changing the color of minDate in react-calender when any other date is selected
- React-select & search in options
- How can I access the local storage on page reload in redux store?
- Selfhosted Azure DevOps Agent running as NetworkService not able to complete npm install and npm build
- Deploying new Webpack bundle causes error until page refresh
- When clicked on button increase value by 3 and when reached array length reset it to 0
- I want to Link my NEXT.js project with a static website
- Knex migrations with Electron and sqlite?
- javascript find() in nested array
- How to call a method with an argument sometimes and sometimes no argument passed using javascript and react?
- Primereact: Warning: Encountered two children with the same key,
- Refresh react app, 404 error. React router issue
- synchronize react app with google sheets
- How can I set some css to a react NumPad component?
- React Autocomplete with Material UI
- Material UI AutoComplete not rendering on remote dataSource in React application
- How CKEditor 5 works at Next.JS?
- Defining command to be run with dotnet watch
- How do you increase the select menu content height?
- Test component use custom hook react-testing-library
- React/Styled-Components: Need to hand roll a dropdown with multiple versions that a developer could use by passing a type in
- npm ERR! code ERR_SOCKET_TIMEOUT on creating new React project when using npx create-react-app
- How does currying work in ReactJS with setState hook?
- How to fix the "set the request's mode to 'no-cors'" error?
- How to test the "onChange" function who will change the value of state with the hooks
- Nextjs - how to apply styled-jsx to jsx returned from method
- How to Delete individual items from list in react
- Understanding Context in Svelte (convert from React Context)