getting-started

Getting started

Installation

Install @noflux/react package by using npmarrow-up-right:

npm install --save @noflux/react

Example

Here is an Noflux app example. You can also debug it online: https://codesandbox.io/s/z47wLwP8arrow-up-right.

import React, { Component } from 'react';
import { connect, state } from '@noflux/react';

state.set({
  name: 'jack',
});

@connect
export default class App extends Component {
  render() {
    return (
      <div>
        <input onChange={e => state.set('name', e.target.value)} />
        <p> Hello, my name is {state.get('name')} </p>
      </div>
    )
  }
}

Syntax

The connect in Noflux is a "decorator" in ES Next proposalarrow-up-right but also can run in the ES5 environment:

If you use a JavaScript compiler like Babelarrow-up-right, you can use @connect decorator with a sample configuration. Run this command to install decorators plugin:

And modify the .babelrc file to enable the plugin:

Code examples in the rest documents will be written using decorators syntax.

Interfaces

Noflux only exports two interfaces, state and connect

  • state maintains a global unique state and provides methods such as get and set to read/write state.

Noflux uses single source of truth and provide an immutable state, that is similar to Reduxarrow-up-right.

  • connect will track changes in state and re-render components intelligently.

A component will be re-rendered via forceUpdatearrow-up-right, meaning its render method will be called if the value from state.get was changed.

Next steps

I believe you have had a preliminary impression of Noflux. Let's enter the next chapter: basic.

Last updated

Was this helpful?