Coder Social home page Coder Social logo

Comments (9)

reneeichhorn avatar reneeichhorn commented on August 15, 2024

Found out that this can be solved by adding the key prop to the Route component.
props.key = this.state.selfPathname before React.createElement(...)
There is no way to pass a unique key depending on the route currently (from the outside)

from react-keeper.

lanistor avatar lanistor commented on August 15, 2024

@reneeichhorn
If there is a 'cache' property on your Route component? If so, the Detail page will be cached instead of unmounted when url is not matching.

from react-keeper.

reneeichhorn avatar reneeichhorn commented on August 15, 2024

It has one, I'm just using the example given in the repository
@vifird

from react-keeper.

reneeichhorn avatar reneeichhorn commented on August 15, 2024

The main issue is that without the key prop react won't understand what is a new component and what not. Therefore it will just think every route is just the same component. Even when going into a new route.

from react-keeper.

lanistor avatar lanistor commented on August 15, 2024

Yeah, key property is used as ID of a component.
@reneeichhorn

from react-keeper.

reneeichhorn avatar reneeichhorn commented on August 15, 2024

I will give you an example:
Imagine a /product/:id route that uses the Product component. The product component uses componentDidMount to recieve data from the server. (as suggested by react best practices)

Now I navigate to /product/123. Product component is mounted, data for product with id 123 is fetched. Product component get rendered again after retrieving data.
Next I navigate to /product/456. Here is where the issue starts (the following problem appear WITH cache and also WITHOUT cache). The Product component is just rerendered with different props. componentDidMount is not executed again and therefore no new data is retrieved. Product will still display data for the 123 product because new data was not fetched.

With or without caching this should not happen. Without a proper key prop on the Route for React it will look like the same component just with different props, therefore only mounted once. This completely breaks React. And forces us to write workarounds.

from react-keeper.

lanistor avatar lanistor commented on August 15, 2024

@reneeichhorn
Yeah, thanks for your issue. We are repairing this problem.

from react-keeper.

lanistor avatar lanistor commented on August 15, 2024

Good one: next version 3

from react-keeper.

koupeng avatar koupeng commented on August 15, 2024

也遇到了同样的问题,什么时候发布新版本啊?????

from react-keeper.

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.