Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parent view's state to nested (or children) component view. #35

Closed
ohpyupi opened this issue Mar 24, 2017 · 7 comments
Closed

Comments

@ohpyupi
Copy link

ohpyupi commented Mar 24, 2017

It must be very stupid question but I wasn't able to find any sound solution to my question on the web. So I am posting it if I can get help from here.

Basically I want to make nested views. I was able to make nested views. However, I have no idea how to pass parent's state to nested view's component.

I tried below but didin't work

<UIView user={this.state.user}/>

Also, I am curious how parent and child (or nested) views acually communicate in ui-router. Do they follow the typical data flow in react.js? For example, usually I make functions and save data to state in container component (parent) and pass to children component. So technically child components emit events and parent do the actual work responding to the emitted events.

Thanks.

@elboman
Copy link
Member

elboman commented Mar 24, 2017

Hi,
Passing state or any data from a parent UIView to a child one is not as direct as using React data flow via props. The reason for this is that the UIView is in charge of mounting a container component only when the corresponding state in active. This means that in a way the router treats the views as encapsulated.

This does not mean that it cannot be done, just that right now the API are not very friendly for accomplishing it.

We are moving towards an explicit way of rendering the components as pointed here: #26

This way it would be possibile to pass anything you need to the mounted components (on which you have no control right now since is the UIView thats handles the rendering):

<UIView render={(Component, props) =>
  <Component {...props} user={this.state.user} />
} />

Since this API change allows for so many things that we cannot do right now I guess I should get it done ASAP 😅

elboman added a commit that referenced this issue Mar 24, 2017
Add new `render` function prop API. This new API lets you control how
the routed component is rendered by the `UIView`:
```jsx
<UIView render={(Comp, props) => <Comp {…props} />} />
```

BREAKING CHANGE: Rename `Resolves` interface to `UIViewResolves` for
consistency.
BREAKING CHANGE: Rename `InjectedProps` interface to `UIViewResolves`
for consistency.

Closes #35
Closes #26
Closes #13
@ohpyupi
Copy link
Author

ohpyupi commented Mar 25, 2017

I appreciate your answer. However, It's not working.... Do I have to update the module? I installed ui-router module through npm.

Also, using that feature, can I change parent view's state from children view? Then, it will be perfect!

@elboman
Copy link
Member

elboman commented Mar 30, 2017

The example I've shown isn't yet a released API, as it's coming in 0.5.0 which will be released soon. I just need to finish some documentation and we should be good to go. Sorry you have to wait a bit longer.

Now sure what you mean, but to change a view state you just need to transition to a new state, and you can trigger transitions from wherever you need, so I'd say yes you can.

I'll ping you here once 0.5.0 is out!

@ohpyupi
Copy link
Author

ohpyupi commented Apr 1, 2017

Alright. I am looking forward to seeing new feature!! Again I appreciate your answer.

@ohpyupi ohpyupi closed this as completed Apr 1, 2017
@telekid
Copy link

telekid commented Jun 23, 2017

@ohpyupi just wanted to mention that it appears this feature has been released.

@elboman
Copy link
Member

elboman commented Jun 29, 2017

yeah, sorry I forgot to update this issue, the feature has been released as @telekid mentioned. Let us know if you need any help!

@ohpyupi
Copy link
Author

ohpyupi commented Jul 7, 2017

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants