@@ -38,7 +38,7 @@ module React
38
38
39
39
, EventHandlerContext ()
40
40
41
- , spec
41
+ , spec , spec'
42
42
43
43
, getProps
44
44
, getRefs
@@ -244,19 +244,23 @@ type ReactSpec props state eff =
244
244
, componentWillUnmount :: ComponentWillUnmount props state eff
245
245
}
246
246
247
- -- | Create a component specification.
247
+ -- | Create a component specification with a provided state .
248
248
spec :: forall props state eff . state -> Render props state eff -> ReactSpec props state eff
249
- spec st renderFn =
250
- { render: renderFn
251
- , displayName: " "
252
- , getInitialState: \_ -> pure st
253
- , componentWillMount: \_ -> return unit
254
- , componentDidMount: \_ -> return unit
249
+ spec state = spec' (\_ -> pure state)
250
+
251
+ -- | Create a component specification with a get initial state function.
252
+ spec' :: forall props state eff . GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff
253
+ spec' getInitialState renderFn =
254
+ { render: renderFn
255
+ , displayName: " "
256
+ , getInitialState: getInitialState
257
+ , componentWillMount: \_ -> return unit
258
+ , componentDidMount: \_ -> return unit
255
259
, componentWillReceiveProps: \_ _ -> return unit
256
- , shouldComponentUpdate: \_ _ _ -> return true
257
- , componentWillUpdate: \_ _ _ -> return unit
258
- , componentDidUpdate: \_ _ _ -> return unit
259
- , componentWillUnmount: \_ -> return unit
260
+ , shouldComponentUpdate: \_ _ _ -> return true
261
+ , componentWillUpdate: \_ _ _ -> return unit
262
+ , componentDidUpdate: \_ _ _ -> return unit
263
+ , componentWillUnmount: \_ -> return unit
260
264
}
261
265
262
266
-- | React class for components.
0 commit comments