Skip to content

purescript-react/purescript-react-basic-hooks

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

900b926 · Apr 10, 2024
May 24, 2022
Mar 19, 2022
Apr 10, 2024
Jun 4, 2022
Jan 15, 2019
Jun 4, 2022
Apr 9, 2020
Jul 14, 2020
Nov 30, 2021
Oct 25, 2022
May 22, 2022
May 22, 2022
Jun 4, 2022
Oct 25, 2022
Jun 4, 2022

Repository files navigation

react-basic-hooks Build Status

react-basic-hooks is a React hook API for react-basic.

Note: This API relies on React >=16.8.0. For more info on hooks, see React's documentation.

I recommend using PureScript's "qualified do" syntax while using this library (it's used in the examples, the React.do bits). It became available in the 0.12.2 compiler release.

This library provides the React.Basic.Hooks module, which can completely replace the React.Basic module. It borrows a few types from the current React.Basic module like ReactComponent and JSX to make it easy to use both versions in the same project. If we prefer this API over the existing react-basic API, we may eventually replace React.Basic with this implementation.

Example

mkCounter :: Component Int
mkCounter = do
  component "Counter" \initialValue -> React.do
    counter /\ setCounter <- useState initialValue

    pure
      $ R.button
          { onClick: handler_ do
              setCounter (_ + 1)
          , children:
              [ R.text $ "Increment: " <> show counter ]
          }

About

An implementation of React hooks on top of purescript-react-basic

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 18