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

Dynamic Tab Items #3312

Closed
cameronbell opened this issue Oct 10, 2018 · 5 comments
Closed

Dynamic Tab Items #3312

cameronbell opened this issue Oct 10, 2018 · 5 comments

Comments

@cameronbell
Copy link

Version

v4.0.1

Expected behaviour

I'm trying to have a different right tab item for each tab.

Actual behaviour

I'm trying to use renderRightButton but the value of Actions.currentScene each time the renderRightButton prop is called is still the value of the previous screen. Is there a proper way to do this?

<Tabs
    key="record"
    renderRightButton={() => {
        
        // Always prints the tab the user was previously on instead 
        // of the tab they just navigated to
        console.log("Current scene: ", Actions.currentScene); 
        
        return Actions.currentScene === "profile" ? <RightButtonSave /> : null;

    }}
>
@aksonov
Copy link
Owner

aksonov commented Oct 10, 2018

Duplicate of #3165

@aksonov aksonov marked this as a duplicate of #3165 Oct 10, 2018
@aksonov aksonov closed this as completed Oct 10, 2018
@cameronbell
Copy link
Author

Thanks! #3165 was helpful for getting the currentScene within the children scenes of my Tabs scene.

It's still unclear to me how to properly use the current scene stored in mobx to create dynamic tab items, because when renderRightButton is called the value of the observable 'scene' variable in mobx hasn't been updated yet.

Is there a way to refresh the props of the parent Tabs scene from a child scene?

I'm currently calling Actions.refresh() at the top of the render function of my child scene which is working, but I'm not sure if this is the ideal way of achieving this.

@aksonov
Copy link
Owner

aksonov commented Oct 10, 2018

I think it is OK

@cameronbell
Copy link
Author

cameronbell commented Oct 10, 2018

Just noticed that calling Actions.refresh() at the top of the render function like that is giving me the following warning:

Warning: Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.

Thanks for your help

@aksonov
Copy link
Owner

aksonov commented Oct 10, 2018

Make sure to wrap it with setTimeout and not in render (but componentDidMount) or static onEnter

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

2 participants