Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

urs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urs

🔥 React hook for maintaining correct values, in a clean way

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.3K
decreased by-58.26%
Maintainers
1
Weekly downloads
 
Created
Source

useRefState

🔥 React hook for maintaining correct values, in a clean way

🚨 This hook is under active development. Do not use in production! 🚨

Installation

yarn add urs      or     npm i -S urs

Usage

import useRefState from 'urs'

const App = () => {
  const [state, setState] = useRefState()


  // if your state is an object, it will recursively go through and turn everything into getters
  // for instance:
  useEffect(() => {
    setState({ no: 'way' })
  }, [])


  const onClick = () => {
    // to get the actual state you must do
    console.log('value', state.value)
    // if it's an object state, instead of having to do
    console.log('no', state.value.no)
    // you can just do
    console.log('no', state.no)
    // BUT, the caveat is you have to do `state.whatever`
    // you CANNOT destructure like: `const [{ no }, setState] = useState()`
  }

  return (
    <button onClick={handleClick}>Click Me!</button>
  )
}

Options

const [
  state,
  setState
] = useSSR({
  _blockOnUnmount: true, // true by default
  // `_depth` IS NOT IMPLEMENTED YET
  // this will make it recurse into an object
  // however many layers deep. 2 by default
  _depth: 2, // 2 by default
  // the rest of the fields in here are just
  // whatever default state you wanna give
})

Keywords

FAQs

Package last updated on 16 Apr 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc