reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Add support for React hooks

Open rwhitten577 opened this issue 3 years ago β€’ 1 comments

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}
    />
  )
}

rwhitten577 avatar Dec 10 '22 14:12 rwhitten577

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 avatar Dec 10 '22 19:12 picklelo

This was added in #810

picklelo avatar Jun 15 '23 18:06 picklelo