Giter VIP home page Giter VIP logo

Comments (13)

mjackson avatar mjackson commented on March 29, 2024

Absolutely. I realize we're doing this wrong, and welcome any insight you can provide on how to do this correctly. The difference between component instances and descriptors has been one of the most difficult things to work with while building this library. We even have a few warnings in our tests because we're using descriptors instead of instances.

Looking over the cloneWithProps API, it doesn't look like it's intended to be used with descriptors. How should we get a handle on the real components?

from react-router.

ryanflorence avatar ryanflorence commented on March 29, 2024

We could move willTransitionFrom to the actual component maybe?

Sent from my iPhone

On Jun 24, 2014, at 9:28 PM, Michael Jackson [email protected] wrote:

Absolutely. I realize we're doing this wrong, and welcome any insight you can provide on how to do this correctly. The difference between component instances and descriptors has been one of the most difficult things to work with while building this library. We even have a few warnings in our tests because we're using descriptors instead of instances.

Looking over the cloneWithProps API, it doesn't look like it's intended to be used with descriptors. How should we get a handle on the real components?


Reply to this email directly or view it on GitHub.

from react-router.

ryanflorence avatar ryanflorence commented on March 29, 2024

had a conversation with @sebmarkbage, the only way to get a handle on the actual instance is the return value of React.renderComponent which we can't use, or refs.

I'm thinking we can maybe add a ref here, which can simply be the name of the route:

https://github.com/rpflorence/react-nested-router/blob/master/modules/components/Route.js#L442

And then instead of storing it on match, look it up on this.refs[routeName] when we pass the component in here:

https://github.com/rpflorence/react-nested-router/blob/master/modules/components/Route.js#L387

from react-router.

sophiebits avatar sophiebits commented on March 29, 2024

Right – with the new refs (not landed yet), you will be able to do something like:

var ref = React.createRef();
props.ref = ref;
match.handlerInstance = route.props.handler(props);

and then use ref.then(...) to resolve it into an actual component instance. (With the current refs, the component instance is attached as a ref to the component "owner", which is basically the deepest render call on the stack at the time of the descriptor's creation. We're switching the API because of situations like this where it's not obvious who the owner is.)

from react-router.

mjackson avatar mjackson commented on March 29, 2024

@rpflorence Where would we get this.refs from? The way the code works currently, all we ever have is descriptors. I'm pretty sure if we say route.refs that we're not any better off than we are now.

Maybe we need a RouteHandler mixin.. but that requires you to say mixin: [Router.Mixin] on every single component you want to use in your routes, which is not ideal.

from react-router.

ryanflorence avatar ryanflorence commented on March 29, 2024

We can bank on the root route I think, can't we?

On Wed, Jun 25, 2014 at 2:15 PM, Michael Jackson [email protected]
wrote:

@rpflorence https://github.com/rpflorence Where would we get this.refs
from? The way the code works currently, all we ever have is descriptors.
I'm pretty sure if we say route.refs that we're not any better off than
we are now.

Maybe we need a RouteHandler mixin.. but that requires you to say mixin:
[Router.Mixin] on every single component you want to use in your routes,
which is not ideal.


Reply to this email directly or view it on GitHub
#47 (comment)
.

from react-router.

mjackson avatar mjackson commented on March 29, 2024

Not really. The current API delegates to users to call React.renderComponent, so all we ever see is descriptors.

If we went one level higher we could get a handle on the components themselves, or we could wait until the new refs @spicyj mentioned land in React proper.

from react-router.

sophiebits avatar sophiebits commented on March 29, 2024

all we ever see is descriptors

Not quite true – in the componentWillMount and componentDidMount hooks for the top-level Route, this refers to the Route component instance. If the Route's render method is the lowest on the stack when the descriptor that has a ref is created, the ref will be attached to that Route instance.

from react-router.

mjackson avatar mjackson commented on March 29, 2024

@spicyj Ah, good to know. We may be able to work with that.

from react-router.

WickyNilliams avatar WickyNilliams commented on March 29, 2024

I'm getting this warning when checking state in my component's willTransitionFrom method. It looks like this fix hasn't landed in a tagged version yet. Are there plans to release any time soon, or is there going to be a cumulative update?

from react-router.

ryanflorence avatar ryanflorence commented on March 29, 2024

thanks for the reminder to release something :)

I just published v0.2.1

On Mon, Jul 14, 2014 at 10:21 AM, Nick Williams [email protected]
wrote:

I'm getting this warning when checking state in my component's
willTransitionFrom method. It looks like this fix hasn't landed in a
tagged version yet. Are there plans to release any time soon, or is there
going to be a cumulative update?


Reply to this email directly or view it on GitHub
#47 (comment)
.

from react-router.

WickyNilliams avatar WickyNilliams commented on March 29, 2024

I was hoping it'd be a welcomed reminder :-)

Thanks, I'll test tomorrow.

from react-router.

WickyNilliams avatar WickyNilliams commented on March 29, 2024

Worked a treat, thanks

from react-router.

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.