react-native-paper
react-native-paper copied to clipboard
BottomNavigation|How to pass props in renderScene?
Hi, Dear developers, If I want to add a props to components in BottomNavigation, How can I do?
Some code like this :
const MyComponent = () => {
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{key: 'music', title: 'Music', icon: 'gift'},
{key: 'recents', title: 'Recents', icon: 'history'},
{key: 'todo', title: 'TodoList', icon: 'github'},
{key: 'albums', title: 'Albums', icon: 'lock'},
]);
const renderScene = BottomNavigation.SceneMap({
music: MusicRoute,
recents: RecentsRoute,
todo: TodoList,
albums: AlbumsRoute,
});
return (
<BottomNavigation
navigationState={{index, routes}}
onIndexChange={setIndex}
renderScene={renderScene}
/>
);
};
I have try to add directly like this, but got an error.
const renderScene = BottomNavigation.SceneMap({
music: MusicRoute,
recents: RecentsRoute,
**todo: <TodoList test={test}/>,**
albums: AlbumsRoute,
});
So I open a issue to ask
Thank you very much!
Hey! Thanks for opening the issue. The issue doesn't seem to contain a link to a repro (a snack.expo.dev link or link to a GitHub repo under your username).
Can you provide a minimal repro which demonstrates the issue? A repro will help us debug the issue faster. Please try to keep the repro as small as possible and make sure that we can run it without additional setup.
Couldn't find version numbers for the following packages in the issue:
react-nativereact-native-paperreact-native-vector-icons
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.
Hey @momolly1024, please check the following snack, I hope it will help you.
Hey @momolly1024, please check the following snack, I hope it will help you.
Hello @lukewalczak. I'm working with BottomNavigation and I'm facing an issue. Please check this Snack out, it's a fork of your last reply.
Steps:
- go to Notifications tab;
- press the "Notification - Add" button;
- watch the relative counter increase;
- press the "MyComponent - Add" button;
- watch the Notification counter set to 0 again.
Is there a way to prevent this behaviour? One solution may be lifting the state of Notification to MyComponent, but I would like to know if there are some alternatives.