npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-lingost

v2.2.0

Published

Best Static-Outer-State For React

Downloads

5

Readme

install

npm install react-lingost

Usage

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

import { createState } from 'react-lingost'

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

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 }
}

// `function stateToProps()`  에서 사용되는 state값은 항상 'String', 'Number', 'Boolean' 형태여야합니다
// The state value used in `function stateToProps ()` should always be of type 'String', 'Number', 'Boolean'

// `return {user: state.user}` 처럼 'Object'를 반환하지 말고, `return {nickname: state.user.nickname}`처럼 'String', 'Number', 'Boolean'를 반환하세요.
// `return { user:{ nickname: state.user.nickname } }` 이런 형태도 가능합니다.
// state를 사용한 값에 대해서만 'String', 'Number', 'Boolean'가 반환되게 해주세요.

// Do not return 'Object' like `return {user: state.user}`, but return 'String', 'Number', 'Boolean' like `return {nickname: state.user.nickname}`
// `return {user: {nickname: state.user.nickname}}` This type is also possible.
// Just let 'String', 'Number', 'Boolean' be returned for values using state.

Example

Use with the component wrapper function, such as LangReloader in react-g-lang.

react-g-langLangReloader와 같은, component wrapper function과 함께 쓰기

  • Before
import { setLanguage, setLanguages, onChangeLanguage } from 'g-lang'
import { lang, LangReloader } from 'react-g-lang'

export default LangReloader(App)
  • After
import { setLanguage, setLanguages, onChangeLanguage } from 'g-lang'
import { lang, LangReloader } from 'react-g-lang'
import { createState, passStateToProps, useMiddleware } from 'react-lingost'

useMiddleware(LangReloader) // <<== add this


export default passStateToProps(App)

Example

createState

import { createState } from 'react-lingost'
// make state
let user = createState('stateName', { title:'abcd' })

// 
/*
`user` variable has the following methods
    setState
    notReRenderedInRealtimeState
*/

passStateToProps

import { passStateToProps } from 'react-lingost'

const stateToProps = ( { stateName } ) => ({
title: stateName.title
})
const __Test1 = (props)=>(<Text>{props.title}</Text>)
const Test1 = passStateToProps( stateToProps )( __Test1 )

// <Test1 /> Component will be <Test1 title='abcd' />

connectProps

import { connectProps, passStateToProps } from 'react-lingost'

const __Test1 = (props) => (<Text>{props.number}</Text>)
const Test1 = connectProps((props) =>
    passStateToProps(({ stateName }) => ({
        number: stateName.number * props.multiply,
    }))(__Test1)
)

// <Test1 multiply={3}/> Component will be <Test1 number={stateName.number * 3} />

useMiddleware

  • See the example above

createState.setState

user.setState({ title:'abcde' })
// The above code will replace <Test1 title='abcd' /> with <Test1 title='abcde' />

user.setState({ descripiton:'hi' })
// The above code will not re-render <Test1 />, because Test1 does not refer to stateName.description