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-state-flex

v0.0.8

Published

React State Flex is a flexible state management library built on top of Redux Toolkit for React applications. It provides a convenient way to manage and persist application state with ease.

Downloads

25

Readme

React State Flex

React State Flex is a flexible state management library built on top of Redux Toolkit for React applications. It provides a convenient way to manage and persist application state with ease.

Installation

To install React State Flex, you can use npm or yarn:

npm install react-state-flex

or

yarn add react-state-flex

Getting Started

Using Flex Services

Utilize the useFlexService hook to interact with your state and perform API requests. This hook provides functions for sending data to your Flex store, detecting state changes, and making API calls with flexible configuration options.

FlexSender(stateName, value)

The FlexSender method dispatches an action to update the state in your Flex store. It takes two parameters:

  • stateName: The name of the state to update.
  • value: The new value to assign to the state.

Example usage:

FlexSender("count", 10);

This code dispatches an action to update the state named "count" to the value 10.

FlexDetector(stateName)

The FlexDetector method detects state changes by retrieving the value of a specific state slice from your Flex store. It takes one parameter:

  • stateName: The name of the state slice to retrieve.

Example usage:

const count = FlexDetector("count");

This code retrieves the current value of the state slice named "count" and assigns it to the variable count.

FlexApi Method

The FlexApi method allows you to make API requests with flexible configuration options. It integrates with the Axios library and provides additional features for managing state, progress tracking, exception handling, and status code handling.

Parameters:

  • config: An object containing the configuration options for the API request. This can include standard Axios configuration options such as method, url, data, etc., as well as the following additional options specific to React State Flex:
    • onUploadProgress: A function to be called periodically with progress information during the upload.
    • onDownloadProgress: A function to be called periodically with progress information during the download.
    • flexstore: An object containing options related to state management. This includes:
      • storeaccess: A boolean indicating whether to store the response data in the Flex store.
      • statename: (Optional) The name of the state slice to store the response data. If not provided, the response data will be stored in a default slice.

Returns:

  • A promise that resolves with the response data from the API request.

Example usage:

async function fetchData() {
  try {
    const response = await FlexApi({
      method: "GET",
      url: "https://api.example.com/data",
      onUploadProgress: (progress) => {
        console.log(`Upload Progress: ${progress}%`);
      },
      onDownloadProgress: (progress) => {
        console.log(`Download Progress: ${progress}%`);
      },
      flexstore: {
        storeaccess: true,
        statename: "myStateName", // Optional: Specify state to store response data
      },
    });
    console.log(response);
    // Handle successful response
  } catch (error) {
    console.error("Error:", error);
    // Handle error
  }
}

Added this FlexProvider in your index.js file

Example usage:

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <FlexProvider element={<App />} />
  </React.StrictMode>,
)

In this example, the FlexApi method is used to send a GET request to the specified URL. Progress tracking functions are provided for upload and download progress. Additionally, the response data is stored in the flex store under the state slice "myStateName". Error handling is included using a try-catch block to handle any errors that may occur during the API request.

Conclusion

React State Flex simplifies state management and provides a seamless way to handle state persistence, API requests, and error handling in your React applications. With its intuitive API and flexible configuration options, you can focus more on building your application logic without worrying about state management complexities.

Contact Information

If you have any questions or queries, please feel free to reach out to me via email at [email protected].