Skip to content

Commit 5d5c9b3

Browse files
authored
Merge pull request #16 from lumihq/michael/stateless-component-helper
Add stateless component helper function
2 parents 9927842 + ab8c958 commit 5d5c9b3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: generated-docs/React/Basic.md

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ The rendering function should return a value of type `JSX`, which can be
1616
constructed using the helper functions provided by the `React.Basic.DOM`
1717
module (and re-exported here).
1818

19+
#### `stateless`
20+
21+
``` purescript
22+
stateless :: forall props. { displayName :: String, render :: props -> JSX } -> ReactComponent props
23+
```
24+
25+
Create a stateless React component.
26+
27+
Removes a little bit of the `react` function's boilerplate when creating
28+
components which don't use state.
29+
1930
#### `createElement`
2031

2132
``` purescript

Diff for: src/React/Basic.purs

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module React.Basic
22
( react
3+
, stateless
34
, createElement
45
, createElementKeyed
56
, fragment
@@ -40,6 +41,24 @@ react { displayName, initialState, receiveProps, render } =
4041
, render: mkFn3 render
4142
}
4243

44+
-- | Create a stateless React component.
45+
-- |
46+
-- | Removes a little bit of the `react` function's boilerplate when creating
47+
-- | components which don't use state.
48+
stateless
49+
:: forall props
50+
. { displayName :: String
51+
, render :: props -> JSX
52+
}
53+
-> ReactComponent props
54+
stateless { displayName, render } =
55+
react
56+
{ displayName
57+
, initialState: unit
58+
, receiveProps: \_ _ _ -> pure unit
59+
, render: \props _ _ -> render props
60+
}
61+
4362
-- | SetState uses an update function to modify the current state.
4463
type SetState state fx = (state -> state) -> Eff (react :: ReactFX | fx) Unit
4564

0 commit comments

Comments
 (0)