ipreact-for-react
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

IPreactForReact

connect data-actions of react-components

see: ipreact

Install

npm i ipreact-for-react

tsconfig.json

{
    "compilerOptions": {
        ...
        "jsx": "react",
        "jsxFactory": "h"
    }
}

Usage

import createStore, { IPreact, Connect } from '../src/ipreact'
import * as React from 'react'
import * as ReactDOM from 'react-dom'
const h = React.createElement

const { connect, dispatch, getState }: IPreact<{ name?: string }> = createStore()({
    name: 'world'
})

interface AppProps { words?: string }
const AppComponent = ({ words }: AppProps) => <h2>{words}</h2>

const connectApp: Connect<AppProps> = connect

const App = connectApp(() => ({
    words: `hello ${getState().name}!`
}))(AppComponent)

let i = 0
setInterval(function () {
    const list = ['prect', 'immutable', 'world', 'ipreact']
     i = (i + 1) % list.length
    dispatch(state => ({name: list[i]}))
}, 1000)

export default ({ el }: { el: HTMLElement }) => {
    ReactDOM.render(<App />, el)
}

hello world

Package Sidebar

Install

npm i ipreact-for-react

Weekly Downloads

7

Version

0.2.4

License

MIT

Unpacked Size

14.5 kB

Total Files

10

Last publish

Collaborators

  • shy2850