Skip to content

Add stateless component helper function #16

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

Merged
merged 3 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions generated-docs/React/Basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ The rendering function should return a value of type `JSX`, which can be
constructed using the helper functions provided by the `React.Basic.DOM`
module (and re-exported here).

#### `stateless`

``` purescript
stateless :: forall props. { displayName :: String, render :: props -> JSX } -> ReactComponent props
```

Create a stateless React component.

Removes a little bit of the `react` function's boilerplate when creating
components which don't use state.

#### `createElement`

``` purescript
Expand Down
19 changes: 19 additions & 0 deletions src/React/Basic.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module React.Basic
( react
, stateless
, createElement
, createElementKeyed
, fragment
Expand Down Expand Up @@ -40,6 +41,24 @@ react { displayName, initialState, receiveProps, render } =
, render: mkFn3 render
}

-- | Create a stateless React component.
-- |
-- | Removes a little bit of the `react` function's boilerplate when creating
-- | components which don't use state.
stateless
:: forall props
. { displayName :: String
, render :: props -> JSX
}
-> ReactComponent props
stateless { displayName, render } =
react
{ displayName
, initialState: unit
, receiveProps: \_ _ _ -> pure unit
, render: \props _ _ -> render props
}

-- | SetState uses an update function to modify the current state.
type SetState state fx = (state -> state) -> Eff (react :: ReactFX | fx) Unit

Expand Down