How do you pass additional props to a tab using SceneMap?
_renderScene = SceneMap({
[TAB_KEY_ONE]: TabOne,
[TAB_KEY_TWO]: TabTwo,
});
TabOne and TabTwo may be functional components, or classes. How do you pass additional props to them?
You can define them as key: () => <TabOne prop={this.props.someProp} />, but note that it won't update as this.prop.someProp changes (it didn't with a normal renderScene function` anyway).
Scenes defined this way also won't update if the state changes, which is great for perf. If you absolutely need them to update, you should use the function manually as you did before.
@satya164 so vague :|
from the official documentation:
IMPORTANT: Do not pass inline functions to SceneMap, for example, don't do the following:
SceneMap({
first: () => <FirstRoute foo={this.props.foo} />,
second: SecondRoute,
});
@flaviolc18 any solution?
@satya164 why your answer contradicts with the document?
@pacozaa my answer is from 2 years ago with an older version of the library :/
@flaviolc18 any solution?
from document, use a custom renderScene function:
const renderScene = ({ route }) => {
switch (route.key) {
case 'first':
return <FirstRoute foo={this.props.foo} />;
case 'second':
return <SecondRoute />;
default:
return null;
}
};
Requesting re-open of this issue, it's not solved yet!
Most helpful comment
You can define them as
key: () => <TabOne prop={this.props.someProp} />, but note that it won't update asthis.prop.somePropchanges (it didn't with a normalrenderScenefunction` anyway).Scenes defined this way also won't update if the state changes, which is great for perf. If you absolutely need them to update, you should use the function manually as you did before.