react-transition-group "-enter(-active)" doesn't work with Preact X
See original GitHub issuereact-transition-group
is partially not working with Preact X.
I’ve created a Preact project with preact-cli
by preact create typescript test (--yarn)
(with typescript template), installed preact@next
and upgraded other packages:
$ yarn add preact@next
$ yarn upgrade
$ yarn remove preact-router
$ yarn add react-router react-router-dom @types/react-router @types/react-router-dom
$ yarn add react-transition-group @types/react-transition-group
After replacing preact-router
by react-router(-dom)
, I’ve changed some codes accordingly.
app.tsx:
import { Component, h } from "preact";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { CSSTransition, TransitionGroup } from "react-transition-group";
import Home from "../routes/home";
import Profile from "../routes/profile";
import Header from "./header";
if ((module as any).hot) {
// tslint:disable-next-line:no-var-requires
require("preact/debug");
}
export default class App extends Component {
public currentUrl?: string;
public render() {
return (
<div id="app">
<Router>
<Header />
<Route
render={({ location }) => {
return (
<TransitionGroup>
<CSSTransition
timeout={6000}
classNames="page"
key={location.key}
>
<Switch location={location}>
<Route
exact
path="/"
component={Home as any}
/>
<Route
exact
path="/profile/"
component={
(() => (
<Profile user="me" />
)) as any
}
/>
<Route
path="/profile/:user"
component={
(({ match }: any) => (
<Profile
user={
match.params
.user
}
/>
)) as any
}
/>
</Switch>
</CSSTransition>
</TransitionGroup>
);
}}
/>
</Router>
</div>
);
}
}
Then -exit(-active)
works while -enter(-active)
doesn’t.
Is there anything I’m missing?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
I cannot get React Transition Group to work. No enter or leave ...
When using CSSTransition for routes, you don't want to use a Switch or a TransitionGroup . You want to put the CSSTransition in...
Read more >Switching to Preact (from React)
Everything you need to know to switch from React to Preact.
Read more >How To Implement Smooth Transitions in React | by Rajat S
In this post, you will see how to use the React-Transition-Group library to implement smoother transitions. In the end, you will be able...
Read more >react-transition-group nextjs Code Example
Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap'). ... Can i open native video playback for both ( ...
Read more >What is the difference between the appear, enter, exit events ...
Coding example for the question React Transition Group: What is the difference between the appear, enter, exit events and the enter, active done...
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 FreeTop 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
Top GitHub Comments
Okay, I think I have a good understanding of what’s happening here. The problem is that
componentDidMount
is called before the DOM has been updated completely. It’s a difficult problem and I have the feeling that this is not just a small fix, but a more involving issue. Not sure if that would make it into the initial X release.Thanks for the two repos 🎉 They’re awesome and help a lot in narrowing the issue down. So far I was able to step through the source of
react-transition-group
and it fails to apply theenter-*
classes. This happens becausefindDOMNode()
returnsnull
and not the expected DOM node. The entering classes are set inside thecomponentDidMount
lifecycle hook. In Preact speak we’re not setting_dom
andc.base
correctly there. Will need to investigate further.