Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hydux-react

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hydux-react

React enhancer for hydux, hydux is an elm-like state manager inspired by Hyperapp, Elmish, Elm, Redux, etc. Working with any vdom library!

  • 0.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hydux-react

React renderer for hydux.

Install

yarn add hydux hydux-react # or npm i hydux hydux-react

Usage

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) =>
    <div>
      <h1>{state.count}</h1>
      <button onClick={actions.down}></button>
      <button onClick={actions.up}>+</button>
    </div>
})

Helpers

PureView

React.PureComponent helper, with which the component uses a shallow prop comparison to determine whether to re-render, which in turn prevents unnecessary re-rendering.


import { PureView } from 'hydux-react'

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

ErrorBoundary

We can use the ErrorBoundary component to catch children's error, which requires a React 16 feature.

import { ErrorBoundary } from 'hydux-react'

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

Counter App

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

Keywords

FAQs

Package last updated on 02 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc