React-NC
Your react state can be anything and anywhere,, Create your universe with React-NC.
Updated
- Version 1.2.0:
RouteControl
is now deprecated,,NCRouter
is now provided for route management.
Installation
npm install react-nc --save
Example
index.js
;;; ; CTRL; ReactDOM;
App.js
; ; { return <div> My name is CTRLstatename <input value=CTRLstatename placeholder="Type to change name" onChange=CTRL /> </div> ; } App;
Commands
CTRL.initializeState(initialState)
Set the initial state of CTRL.
CTRL; console; // Output: My name is iNont.
CTRL.setState(state)
Set state of CTRL, you can use it likes setState()
of react component.
CTRL;CTRL; console; /* Output: { name: "Changed name", title: "React-NC", array: [0, 1, 2, 3]} */
CTRL.resetState()
Reset CTRL state to initial state.
CTRL.forceUpdate()
Force update the component wrapped by StateControl
.
React-NC with NCRouter
NCRouter
helps you manage your routes, it's easy to route to the path you want to.
Note: You can still use CTRL.redirect("/path")
with react-router-dom
same as the previous version
Example
index.js
;;; ; CTRL; ReactDOM;
App.js
; ; ;;; CTRLrouting; { return <NCRouter> <Route default path="/" component=MainPage /> <Route path="/edit" component=EditPage /> <Route path="/detail/{username}" component=DetailPage /> </NCRouter> ; } App;
MainPage.js
; ; { return <div> My name is CTRLstatename <button onClick=CTRLrouting>Edit</button> <button onClick=CTRLrouting>Detail</button> </div> ; } ;
EditPage.js
; ; { return <div> <input value=CTRLstatename placeholder="Type to change name" onChange=CTRL /> <button onClick=CTRLrouting>Back</button> <button onClick=CTRL>Reset</button> </div> ; } ;
DetailPage.js
; ; { return <div> My username: thispropsmatchparamsusername <button onClick=CTRLrouting>To default page</button> </div> ; } ;
Commands
CTRL.routing.setPrefix(prefix)
Set prefix of your routes. Then, all of your paths will be started with that prefix.
CTRLrouting; // If your path is "/edit", it will be "/my-web/edit" in browser url
CTRL.routing.redirect(path)
Redirect to path, path
can be string or object.
CTRLrouting;CTRLrouting; // location will be "/my-web/edit"
or path
as object
CTRLrouting;CTRLrouting; // location will be "/my-web/edit?id=inont#top"
CTRL.routing.replacePath(path)
Replace the current path to path
.
CTRL.routing.query(query)
query
as object, this will change query string on url to query
.
CTRLrouting;CTRLrouting;CTRLrouting; // location will be "/my-web/edit?id=inont"