Comments (13)
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.
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.
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.
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.
@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.
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.
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.
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.
@spicyj Ah, good to know. We may be able to work with that.
from react-router.
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.
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.
I was hoping it'd be a welcomed reminder :-)
Thanks, I'll test tomorrow.
from react-router.
Worked a treat, thanks
from react-router.
Related Issues (20)
- [Docs]: Tutorial missing imports within 'contacts.js'. [ "match-sorter" , "localforage" , "sort-by" ] HOT 1
- [Bug]: history.listen not triggered on hash changes HOT 1
- [Bug]: Update comments recommending to use polyfill.io HOT 3
- [Docs]: Nested Routes are essentially undocumented HOT 5
- [Bug]: unstable_patchRoutesOnMiss is superseded by "*" (404) HOT 3
- [Bug]: unstable_patchRoutesOnMiss leaf ignored when patching sub-trees asyncronously HOT 3
- [Bug]: Functional updates to `useSearchParams` don't get updated values HOT 2
- Update to isbot@5 HOT 1
- [Bug]: `unstable_patchRoutesOnMiss` remote module error-handling HOT 13
- [Bug]: useMatch does not decode params HOT 4
- [Bug]: Could not resolve './utils' from packages/router/index.ts HOT 2
- [Bug]: Link when used with Outlet is not working. It is routing to error page when clicked. HOT 1
- [Bug]: setSearchParams from useSearchParams remove hash HOT 1
- [Bug]: HashRouter need to wrapped twice HOT 1
- [Docs]: docs show reach/router instead of react/router HOT 2
- [Bug]: "react-router-dom-v5-compat" <CompatRouter> doesn't unsubscribe from history potentially causing tests to memory leak HOT 2
- [Bug]: child loader redirect overrides parent loader error HOT 7
- [Bug]: v7_partialHydration with unstable_patchRoutesOnMiss: hydrateFallbackElement not shown on patched routes HOT 3
- [Bug]: Relative path does not work as expected in outlets HOT 1
- [Bug]: useNavigate causes component to rerender HOT 1
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-router.