Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useCapacitorStore is not rerendered on changes made by Preferences.set #21

Open
FreePhoenix888 opened this issue Nov 21, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@FreePhoenix888
Copy link
Member

How to reprodouce

import React from "react";
import {
  CapacitorStoreProvider,
  useCapacitorStore,
} from "@deep-foundation/store/capacitor";
import {
  Card,
  CardBody,
  CardHeader,
  ChakraProvider,
  FormControl,
  FormLabel,
  Heading,
  Stack,
  Switch,
  Text,
} from "@chakra-ui/react";
import { Preferences } from "@capacitor/preferences";

function Content() {
  const key = "aaa";
  const [state, setState] = useCapacitorStore(key, "false");

  return (
    <Stack>
      <Text>State: {state.toString()}</Text>
      <Card>
        <CardHeader>
          <Heading>Data Synchronization</Heading>
        </CardHeader>
        <CardBody>
          <FormControl display="flex" alignItems="center">
            <FormLabel htmlFor="sync-call-history-switch" mb="0">
              Synchronize All Data
            </FormLabel>
            <Switch
              id="sync-call-history-switch"
              onChange={(event) => {
                const { checked } = event.target;
                Preferences.set({ key: key, value: checked.toString() });
              }}
            />
          </FormControl>
        </CardBody>
      </Card>
    </Stack>
  );
}

export default function IndexPage() {
  return (
    <ChakraProvider>
      <CapacitorStoreProvider>
        <Content />
      </CapacitorStoreProvider>
    </ChakraProvider>
  );
}

Additional Info

Screencast.from.11-22-2023.03.05.30.AM.webm
@FreePhoenix888 FreePhoenix888 self-assigned this Nov 21, 2023
@FreePhoenix888 FreePhoenix888 added the bug Something isn't working label Nov 21, 2023
@FreePhoenix888 FreePhoenix888 changed the title useCapacitorStore is not rerendered on changed made by Preferences.set useCapacitorStore is not rerendered on changes made by Preferences.set Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant