React-native-tab-view: How to pass additional props using SceneMap?

Created on 10 May 2017  路  8Comments  路  Source: satya164/react-native-tab-view

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?

Most helpful comment

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.

All 8 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashusdn picture ashusdn  路  4Comments

glennvgastel picture glennvgastel  路  3Comments

nastarfan picture nastarfan  路  3Comments

lubomyr picture lubomyr  路  3Comments

moerabaya picture moerabaya  路  4Comments