Search code examples
react-nativenavigationdispatch

React-native Dispatch action to two tabs at once


I want to re-render two tabs by setParams, it works if i dispatch to one tab, but dispatch to two tabs like code bellow doesn't work

const setParamsAction1 = NavigationActions.setParams({ params: { foo: 'bar' } }, key: 'a' });
const setParamsAction2 = NavigationActions.setParams({ params: { foo: 'bar' } }, key: 'b' });
this.props.navigation.dispatch(setParamsAction1);
this.props.navigation.dispatch(setParamsAction2);

Solution

  • I found out the easiest way is wrapping dispatch inside async function

    async setNavParams(key) {
        await this.props.navigation.dispatch(NavigationActions.setParams({
            params: { foo: 'bar' },
              key: key,
            }))
    }