🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

react-lingost

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-lingost

Best Static-Outer-State For React

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
20
400%
Maintainers
1
Weekly downloads
 
Created
Source

install

npm install react-lingost

Usage

1. create ./lingost/ Directory and create ./lingost/index.js and write below

import { createState } from 'react-lingost'

let user = createState('user', {
    logged: false,
    data:{},
    test:[1,2,3,4],
})

module.exports = {
    user,
}

2. ./app.js

(1) Import react-lingost module

import { passStateToProps } from 'react-lingost'

(2) Enclose the your app component with the passStateToProps function

function stateToProps( { user } ) {
    return {
        logged: user.logged,
        test: user.test[0]
    }
}
export default passStateToProps(stateToProps)(App)

(3) Update State Anywhere

import { user } from './lingost/index.js'

...

user.setState({
    logged: true
}) // update state and reRender

react-lingost

  • react-lingost의 외부 상태는 어디서든 업데이트 할 수있습니다.
  • stateToProps가 변하지 않는다면 re-Rendering 되지 않습니다.
    let user = createState('user', {
        logged: false,
        data:{},
        test:[1,2,3,4],
    })
    function stateToProps( { user } ) {
        return {
            logged: user.logged,
            test: user.test[0]
        }
    }
    export default passStateToProps(stateToProps)(App)
    
    
    user.setState({
        test:[1,2,3]
    })
    /*
    이 경우에는 setState를 호출해도 re-Rendering 되지 않습니다.
    App은 { test: user.test[0] } 를 참조하고 있는데
    위의 setState를 호출하더라도 user.test[0]의 결과는 바뀌지 않기 때문입니다.
    
    In this case, calling setState does not re-render.
    App refers to {test: user.test [0]}
    This is because calling setState does not change the result of user.test [0].
    */
    

Precautions

// dont use below, it will not working
function stateToProps( state ) {
    return { state }
}

// you can use,
function stateToProps({ user }) {
    return { nickname: user.nickname }
}

// or
function stateToProps(state) {
    return { nickname: state.user.nickname }
}

FAQs

Package last updated on 17 Jul 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