Skip to content

xeontem/purescript-react-basic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-react-basic

This package implements an opinionated set of bindings to the React library, optimizing for the most basic use cases.

Features

  • All React DOM elements and attributes are supported.
  • An intuitive API for specifying props - no arrays of key value pairs, just records.
  • Attributes are optional, but type-checked. It is a type error to specify href as an integer, for example.

Getting Started

You can install this package using Bower:

bower install git@github.com:lumihq/purescript-react-basic.git

Here is an example component which renders a label read from props along with a counter:

module React.Basic.Example where

import Prelude

import Data.Function.Uncurried (mkEffFn1)
import React.Basic as R

-- The props for the component
type ExampleProps =
  { label :: String
  }

-- The internal state of the component
type ExampleState =
  { counter :: Int
  }

-- Create a component by passing a record to the `react` function.
-- The `render` function takes the props and current state, as well as a
-- state update callback, and produces a document.
example :: R.ReactComponent ExampleProps
example = R.react
  { initialState: { counter: 0 }
  , render: \{ label } { counter } setState ->
      R.button { onClick: mkEffFn1 \_ -> do
                            setState { counter: counter + 1 }
               }
               [ R.text (label <> ": " <> show counter) ]
  }

This component can be used directly from JavaScript. For example, if you are using purs-loader:

import {example as Example} from 'React.Basic.Example.purs';

const myComponent = () => (
  <Example label='Increment' />
);

About

An opinionated set of bindings to the React library, optimizing for the most basic use cases

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PureScript 94.5%
  • JavaScript 5.5%
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy