React-native-paper: Is it possible to use BottomNavigation with React Hooks?

Created on 19 Apr 2020  路  1Comment  路  Source: callstack/react-native-paper

I tried to use BottomNavigation with React Hooks, useState.

But i am getting error while trying to change route.

Anyone tried before?

question

Most helpful comment

I write it like this and it's working fine

const [nav, setNav] = useState({ index: 0, routes: [ { key: 'music', title: 'Music', icon: 'album' }, { key: 'albums', title: 'Albums', icon: 'album' }, { key: 'recents', title: 'Recents', icon: 'history' }, ], });

<BottomNavigation navigationState={nav} onIndexChange={(index) => _handleIndexChange(index)} renderScene={_renderScene()} />

function _handleIndexChange(index) { setNav({ ...nav, index }) };

function _renderScene() { return BottomNavigation.SceneMap({ music: ResumeFeed, albums: ResumeFeed, recents: ResumeFeed, }); }

Good luck

>All comments

I write it like this and it's working fine

const [nav, setNav] = useState({ index: 0, routes: [ { key: 'music', title: 'Music', icon: 'album' }, { key: 'albums', title: 'Albums', icon: 'album' }, { key: 'recents', title: 'Recents', icon: 'history' }, ], });

<BottomNavigation navigationState={nav} onIndexChange={(index) => _handleIndexChange(index)} renderScene={_renderScene()} />

function _handleIndexChange(index) { setNav({ ...nav, index }) };

function _renderScene() { return BottomNavigation.SceneMap({ music: ResumeFeed, albums: ResumeFeed, recents: ResumeFeed, }); }

Good luck

Was this page helpful?
0 / 5 - 0 ratings