Reactでタブに関数を渡してやる方法

  • 結論
  • 動機
  • 原理
  • まとめ

結論

こんな感じ

const MainTab = createBottomTabNavigator();

module.exports = () => {
const [CurrentID, SetCurrentID] = useState(false);
return (
<NavigationContainer>
<MainTab.Navigator
style={{
position: 'absolute',
zIndex: 0,
}}>
<MainTab.Screen
name="Home"
children={() => <Home SetCurrentID={SetCurrentID} />}
options={{
title: 'ホーム',
}}
/>
<MainTab.Screen
name="Library"
component={Home}
setMethod={SetCurrentID}
options={{
title: 'ライブラリ',
}}
/>
</MainTab.Navigator>
<Player CurrentID={CurrentID} SetCurrentID={SetCurrentID} />
</NavigationContainer>
);
};

コメント

  1. より:

    初見です!

タイトルとURLをコピーしました