Giter Club home page Giter Club logo

purescript-react-basic's Introduction

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 (soon, events are a work in progress).
  • 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 [email protected]: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 Control.Monad.Eff.Uncurried (mkEffFn1)
import React.Basic (ReactComponent, react)
import React.Basic.DOM as R

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

-- 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 :: ReactComponent ExampleProps
example = react
  { initialState: { counter: 0 }
  , receiveProps: \_ _ _ -> pure unit
  , render: \{ label } { counter } setState ->
      R.button { onClick: mkEffFn1 \_ -> do
                            setState \s -> { counter: s.counter + 1 }
               , children: [ 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' />
);

purescript-react-basic's People

Contributors

megamaddu avatar spicydonuts avatar paf31 avatar tippenein avatar codedmart avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.