1

ここに画像の説明を入力

ここに画像の説明を入力

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]
  );
4

0 に答える 0