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

react-stateful-function

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-stateful-function

React Statful Function

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

React Stateful Function

PRsBadge npm npm

Implement react state into your function component in just One Step!

  • Use funcDidMount instead of componentDidMount
  • Use funcWillUnmount instead of componentWillUnmount
  • Use funcDidUpdate which is easier than of componentDidUpdate
  • Construct your state and update it inside any function component
  • Very simple way to change state, just like Component setState !
  • No hooks background needed at all, just import and use!

Instalation

npm i react-stateful-function - OR - yarn add react-stateful-function

Usage Example

import React from 'react';
import { constructState, funcDidMount, funcWillUnmount, funcDidUpdate } from './src';


const ReactStatefulFuncComponentExample = () => {

    const {
        state, // <= Access and Use state, just like this.state !
        setState, // <= Change and Update state, just like this.setState !
        resetState, // <= Reset state to its initial values
    } = constructState({ count: 0, toggle: false }); // <= Initialize state, just like this.state={} !


    const { count, toggle } = state; // Decounstrct for easier usage.


    funcDidMount(() => {

        // ComponentDidMount replacement

    });

    funcWillUnmount(() => {

        // ComponentWillUnmount replacement

    });

    funcDidUpdate([count], () => {

        // ComponentDidUpdate replacement
        // Comparing values' changes within renders
        // Will be called if `count` value is changed
        // You can make more `funcDidUpdate` with other values

    });


    // Component Render return
    return (
        <>
        {/* Your Component's JSX elements */}
        </>
    );

};

Keywords

FAQs

Package last updated on 23 Jan 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