Coder Social home page Coder Social logo

Comments (4)

Oba-One avatar Oba-One commented on July 23, 2024 3

@Sampite I' using reach router not react router. Do you know any examples for reach?

from react-spring.io.

th3oxen avatar th3oxen commented on July 23, 2024 2

@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.

Sampite avatar Sampite commented on July 23, 2024 1

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.

joshuaellis avatar joshuaellis commented on July 23, 2024

Moving to react-spring.io where this should probably live.

from react-spring.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.