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

Add support for React hooks #55

Closed
rwhitten577 opened this issue Dec 10, 2022 · 2 comments
Closed

Add support for React hooks #55

rwhitten577 opened this issue Dec 10, 2022 · 2 comments
Labels
feature request A feature you wanted added to reflex
Milestone

Comments

@rwhitten577
Copy link

rwhitten577 commented Dec 10, 2022

Hi guys, cool project! I'm trying to migrate a basic Chakra + FastAPI app to Pynecone but a bit stuck on implementing the classic Chakra ColorModeSwitcher component.

Is there any way currently to access the color mode hooks? I imagine there are use cases beyond these hooks, but being able to use hooks from other libraries.

Example component to implement:

import * as React from "react"
import {
  useColorMode,
  useColorModeValue,
  IconButton,
  IconButtonProps,
} from "@chakra-ui/react"
import { FaMoon, FaSun } from "react-icons/fa"

type ColorModeSwitcherProps = Omit<IconButtonProps, "aria-label">

export const ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = (props) => {
  const { toggleColorMode } = useColorMode()
  const text = useColorModeValue("dark", "light")
  const SwitchIcon = useColorModeValue(FaMoon, FaSun)

  return (
    <IconButton
      size="md"
      fontSize="lg"
      variant="ghost"
      color="current"
      marginLeft="2"
      onClick={toggleColorMode}
      icon={<SwitchIcon />}
      aria-label={`Switch to ${text} mode`}
      {...props}
    />
  )
}
@picklelo
Copy link
Contributor

Thanks for raising this issue.

Currently there's no good way to use your own React hooks in Pynecone. But this is a feature we want to add because like you said, there are other libraries that use hooks for functionality.

This change requires some core updates to the compiler, so may be a bit more involved. But we will add it to our roadmap.

@picklelo
Copy link
Contributor

This was added in #810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature you wanted added to reflex
Projects
None yet
Development

No branches or pull requests

2 participants