An open API service indexing awesome lists of open source software.

https://github.com/hydux/hydux-react

Hydux + React = :heart:
https://github.com/hydux/hydux-react

elm elmish hydux hyperapp react redux

Last synced: 7 months ago
JSON representation

Hydux + React = :heart:

Awesome Lists containing this project

README

          

# hydux-react
React renderer for hydux.

## Install
```sh
yarn add hydux hydux-react # or npm i hydux hydux-react
```

## Usage

```js
import _app from 'hydux'
import withPersist from 'hydux/lib/enhancers/persist'
import withReact, { React } from 'hydux-react'

let app = withReact()(_app)

export default app({
init: () => { count: 1 },
actions: {
down: () => state => ({ count: state.count - 1 }),
up: () => state => ({ count: state.count + 1 })
},
view: (state: State, actions: Actions) =>


{state.count}



+

})
```

## Helpers

### PureView

[React.PureComponent](https://reactjs.org/docs/react-api.html#reactpurecomponent) helper, with which the component uses a shallow prop comparison to determine whether to re-render, which in turn prevents unnecessary re-rendering.

```tsx

import { PureView } from 'hydux-react'

export function View(props) {
return (
// The props passed to PureView would be shallow compared and determine whether diff and render child components.
{(props) => } // here we pass function as children to avoid executing child components' render function.

)
}

```

## ErrorBoundary

We can use the ErrorBoundary component to catch children's error, which requires a [React 16 feature](https://reactjs.org/docs/error-boundaries.html).

```tsx
import { ErrorBoundary } from 'hydux-react'

export function View(props) {
return (
void} // Custom error handler function
renderMessage={(error, errorInfo) => React.ChildNode} // Custom error message renderer, default is `return null`
>
{() => } // here we pass function as children to catch errors in child components' render function.

)
}
```

## Counter App

```sh
git clone https://github.com/hydux/hydux-react.git
cd examples/counter
yarn # or npm i
npm start
```

Now open http://localhost:8080 and hack!

## License

MIT