getting-started
Getting started
Installation
Install @noflux/react package by using npm:
npm install --save @noflux/reactExample
Here is an Noflux app example. You can also debug it online: https://codesandbox.io/s/z47wLwP8.
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 proposal but also can run in the ES5 environment:
class App extends Component {
//...
}
export default connect(App);If you use a JavaScript compiler like Babel, you can use @connect decorator with a sample configuration. Run this command to install decorators plugin:
npm install --save-dev babel-plugin-transform-decorators-legacyAnd modify the .babelrc file to enable the plugin:
{
"plugins": ["transform-decorators-legacy"]
}Code examples in the rest documents will be written using decorators syntax.
Interfaces
Noflux only exports two interfaces, state and connect。
statemaintains a global unique state and provides methods such asgetandsetto read/write state.
Noflux uses single source of truth and provide an immutable
state, that is similar to Redux.
connectwill track changes instateand re-render components intelligently.
A component will be re-rendered via forceUpdate, meaning its
rendermethod will be called if the value fromstate.getwas 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?