Comments (4)
@Sampite I' using reach router not react router. Do you know any examples for reach?
from react-spring.io.
@Oba-One here's a sandbox using reach router. However there's few things that make the transition not working as expected:
- Using this transition:
const transition = useTransition(route, r => r.pathname, {
from: { opacity: 0, transform: "translateX(100%)" },
enter: { opacity: 1, transform: "translateX(0)" },
leave: { opacity: 0, transform: "translateX(-50%)" },
unique: true,
reset: true
});
doesn't animate correctly in chrome, but lowering the from
to something like translateX(90%)
works.
- Despite what's being said in the reach router documentation about animations, passing the location received from
<Location>
to the<Router>
, causes the new location to be rendered immediately. I used local state even though I think that by doing so, a render pass is wasted returning null.
if (route.pathname !== location.pathname) {
setRoute(location); //Cause a re-render with the new location as state
return null;
}
P.S. Those issues are not present if using react-router-dom.
Edit:
By reading react router documentation I found out that
The useLocation hook returns the location object that represents the current URL. You can think about it like a useState that returns a new location whenever the URL changes.
So I guess that what I am doing with setRoute
mimick what they're doing with useLocation
Also is worth noticing that in react router, if you put anything in between the <Switch>
and its <Route>
s, it will render the current location immediately, just like reach router.
<Switch location={location}>
<div> // This won't work
<Route path="/" exact component={ComponentA} />
<Route path="/b" component={ComponentB} />
</div>
</Switch>
from react-spring.io.
Hey @Oba-One !
I also use react-spring and react-router together, there is a nice example that I used as a base and tailored for my needs at https://www.react-spring.io/docs/hooks/use-transition Demos section at the bottom.
It is currently referring to this sandbox
Hope it helps.
from react-spring.io.
Moving to react-spring.io
where this should probably live.
from react-spring.io.
Related Issues (20)
- Memory leak on examples page HOT 4
- Fix or remove Controller example on "Gotchas" page
- Fix mobile layout HOT 1
- Use react-live or similar for the examples HOT 4
- Code sample text color is white on white HOT 2
- Add some guides HOT 3
- Update the renderprops API docs
- config.decay prop should be effected by friction
- Document recommendations for building accessible animations HOT 2
- https://www.react-spring.io website is down HOT 2
- Warnings and Contributing Guides HOT 4
- Looping a Trail Component HOT 2
- useTransition does not return a function in v9 HOT 1
- Document shorthand/shortcuts for css transform properties. HOT 1
- ✨ SUGGESTIONS ✨ HOT 4
- Please help to find documentation for v8 HOT 1
- Where i can found the react-spring v8.** documentation (old react-spring.io) HOT 3
- Better documentation needed to migrate velocity props from v8 to v9 HOT 3
- Is onDestroyed meant to be deprecated in v9, if so - what replaces it? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-spring.io.