useSelector
で見つけた、必要なテーマ タイプのステータスを取得します settings.item.colorScheme
。
選択した言語をクリックしてBottomSheet
変更できる があります。この変更により、 のステータスredux
も変更settings
されuseSelector
ます。
問題は、内部の状態がuseCallback
変更されないことです。少なくとも、bottomSheet
メニューを閉じてから再度開いたときにのみ変更されます。
useCallback
内部で定義されているものの中で、更新されたステータスを確認するにはどうすればよいですか?
に引数として渡そうとしましたuseCallback
が、うまくいきません。
コード:
const dispatch = useDispatch();
const settings = useSelector((state) => state.settings);
const { present, dismiss } = useBottomSheetModal();
const theme = [
{ title: 'Light', value: 'light' },
{ title: 'Dark', value: 'dark' }
];
const bottomSheetTheme = useCallback(
(newValue, id) => {
present(
<View style={{ flex: 1, backgroundColor }}>
<Text>{settings.item.colorScheme}</Text>
{theme.map(({ title, value }) => {
return (
<TouchableWithoutFeedback
key={value}
onPress={() => {
//dismiss();
changeButtonTheme(value);
}}>
<View
style={[
Layout.row,
Layout.rowHCenter,
Gutters.tinyVMargin,
Gutters.tinyHMargin,
]}>
<View style={[Layout.fill]}>
<Text>{title}</Text>
</View>
{settings.item.colorScheme === value ? (
<Svgs.RadioButton size={32} color={backgroundColor} />
) : (
<Svgs.RadioButtonEmpty size={32} color={backgroundColor} />
)}
</View>
</TouchableWithoutFeedback>
);
})}
</View>,
{
snapPoints: ['25%'],
animationDuration: 10,
overlayComponent: BottomSheetOverlay,
overlayOpacity: 0.5,
dismissOnOverlayPress: true,
//handleComponent: handle,
//backgroundComponent: BlurredBackground,
//onChange: handleChange,
}
);
},
[settings]
);