+1
-1
| { | ||
| "name": "hyperwrap", | ||
| "version": "1.0.10", | ||
| "version": "1.0.11", | ||
| "description": "Makes React simple and functional", | ||
@@ -5,0 +5,0 @@ "main": "index.tsx", |
+14
-11
@@ -93,15 +93,11 @@ # Meet hyperwrap | ||
| - We've moved `changeThing` to it's own module | ||
| - We've made `state` and `actions` as optional props to our functional component. | ||
| - We've made `state` and `actions` optional props to our functional component. | ||
| - We've set default values for `state` and `actions`. | ||
| _This lets us to inject mock values for state and actions, for easier testing + now it's a pure function_ | ||
| Our component is now a pure function. It relies entirely on what is passed into it. | ||
| It doesn't create any direct side effects. | ||
| This means we can inject mock values for state and actions, for easier testing. | ||
| ```javascript | ||
| import * as React from 'react'; | ||
| import { State } from '../../../state/state'; | ||
| import { getState } from 'hyperwrap'; | ||
| import { changeThing } from './change-thing.function'; | ||
| interface Props { | ||
@@ -116,7 +112,14 @@ state?: State; | ||
| export const Home = ({state, actions}: Props = { state: getState(), actions: actionsCollection } ) => { | ||
| export const Home = ( | ||
| {state, actions}: Props = { | ||
| state: getState(), | ||
| actions: actionsCollection | ||
| } | ||
| ) => { | ||
| const _state = state || getState(); | ||
| const _actions = actions || actionsCollection; | ||
| return ( | ||
| <div> | ||
| <p>{state!.thing}</p> | ||
| <button onClick={(e) => {actions!.changeThing(e, 'bob')} }>push</button> | ||
| <p>{_state.thing}</p> | ||
| <button onClick={(e) => {_actions.changeThing(e, 'bob')} }>push</button> | ||
| </div> | ||
@@ -123,0 +126,0 @@ ); |
6498
0.63%182
1.68%