score:15
React is just changing the content of the DOM because that's all that changed. Give the elements unique keys to make them animate.
if (this.state.showOne)
{
result = <div key="one">One</div>
}
else
{
result = <div key="two">Two</div>
}
score:1
I used Michelle Treys answer to solve a similar problem using React-Router (1.0.1). Its not clear from the api that the key is needed. I was following React-routers suggestion to render a routes children in a parent as follows:
render() {
return (
<div id='app-wrapper'>
<ReactTransitionGroup component='div' className='transition-wrapper'>
{this.props.children}
</ReactTransitionGroup>
</div>
);
}
However the componentWillEnter only triggered on page load. Following Michelle's solution, I cloned a the children as per the react-router updates and added a key as follows:
render() {
const { location } = this.props;
return (
<div id='app-wrapper'>
<ReactTransitionGroup component='div' className='transition-wrapper'>
{React.cloneElement(this.props.children, {
key: location.pathname,
})}
</ReactTransitionGroup>
</div>
);
}
Thanks for the fix. Cheers
Source: stackoverflow.com
Related Query
- ReactJS Transitions - Why doesn't this work?
- ReactJS. - Why does this work in ReactJS and not the other way
- Why does hot reloading not work for reactjs visual studio 2019 template
- GET request works with Postman but why doesn't it work with ReactJS fetch?
- Why number validate rule doesnt work in antd
- Why doesn't react-sticky work in this simple example?
- Why the input doesnt work when generated by React
- why my current project in reactjs included this "theme": "lessc --js src/App.less src/App.css", in package.json scripts?
- Why ES6 ComputedPropertyName does not work with this react js code?
- Why this doesn't work with recompose and ramda?
- Why won't it work this way to display what the user has clicked to appear in the modal?
- Why is this undefined within reactjs component method
- This keyword in ReactJs and why we loose the context
- Why does this mock api not work as expected?
- Why ASYNC AWAIT doesnt work well in use effect in react
- ref does not work in this reactjs component
- Why doesn't work button that increases the number (simulation of likes)? How to fix this problem?
- ReactJS why will this state change not render? What am I doing wrong?
- Why doesn't this d3 component work when the input type changes?
- I can't work out why this Laravel API keeps returning a 404
- API call with ReactJs Component doesnt work
- Why did setState not work in this case in NextJS?
- How does this code work with reactJs
- reactJs my event.preventDefault(); doesnt work
- I am new to the React and I don't know why this doesn't work
- Why is this reactjs useEffect function running endlessly?
- Why does adding/removing curly braces in this arrow function cause the text to not display for a ReactJS component?
- Why inline styling doesnt work in react on components?
- Why won't this OpenLayers map won't display in ReactJS application?
- Element obtaining value from input only updating after the second time I press enter. Why is this happening? - ReactJS
More Query from same tag
- Dropdown clearing but state remains after component update
- React prop containing function is not defined
- how to add props in route component in react-router-dom v6
- ReactJs with big forms, having a lag when type in text fields
- Conditionally change order of rendering React component
- react-router-dom history.goBack() not working on Firefox and Safari
- Search over json object (react)
- Arrow function expected a return value
- how to call a component into anther in reactjs
- properties file in reactJS
- Display 1 value at a time from json file
- Write this.props.element beside a HTML tag in JSX
- How do I find the React DOM node that represents its actual html element?
- ReactSearchBox Not Loading Array From Fetch
- Which is the react way of complex conditional rendering?
- React-router: How to manually invoke Link in new window?
- React Ant design Why are certain hours and minutes of days after today disabled?
- How to set environment variables on React with custom webpack
- React deployment to firebase using github actions
- Uncaught TypeError: Cannot read property 'files' of undefined
- I changed the functional component containing the FORMIK to the class component and got errors. Why?
- how to convert class component to function component?
- change color of burger menu depending on the background of the section
- How do I edit a task in a react/mysql application?
- Do we need to do cross browser testing of React application
- why my shopping cart not re-render after the change the state of the product
- function returning opposite boolean value to what I expected
- In React Hook, how can I change specific value of useState array?
- While I go to submit data into Database table I face this error in browser console: Uncaught (in promise) Error: Request failed with status code 404
- React 'this' undefined when adding table row