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

Export a hook for more generic solution #451

Open
sagarpanchal opened this issue Jun 11, 2024 · 0 comments
Open

Export a hook for more generic solution #451

sagarpanchal opened this issue Jun 11, 2024 · 0 comments

Comments

@sagarpanchal
Copy link

const [otp, setOtp] = React.useState("");

const { getContainerProps, getInputProps } = useOtpInput({
  // we may wrap setState in our hook, if it is convenient, and only take initialValue here
  value: otp,
  setValue: setOtp,
});

const test = (
  <Box {...getContainerProps()} display='flex' flexDirection="row" gap="1em">
    {Array.from({ length: 4 }).map((_, index) => (
      <Box key={index} gap="1em" border="1px solid #000" borderRadius="0.25em" height="3em" width="3em" >
        <Box as="input" {...getInputProps(index)} type="text" key={index} />
      </Box>
    ))}
  </Box>
);

This way we can use @chakra/react's <Box /> instead of div and not limit styles to containerStyle attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant