react-use-config
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

react-use-config

react-use-config is a React Hook (useConfigParam) for dynamically retrieving configuration parameters with well-defined priorities.

Build Status License Coverage Version PRs Welcome Downloads


Features

The useConfigParam hook retrieves parameter values in the following priority order:

  1. Query Parameter: Retrieved directly from the URL.
  2. Environment Variable: Defined in the .env file (prefixed with REACT_APP_).
  3. Default Value: A fallback provided by the user.

Visual Overview

Streamlining React Configurations

Streamlining React Configurations

Features Enhancing useConfigParam

Features Enhancing useConfigParam Hook

Configuration Retrieval Funnel

Configuration Value Retrieval Funnel


Usage Example

import useConfigParam from 'react-use-config';

// Retrieve the 'geoServer' parameter with a default value
const geoServer = useConfigParam('geoServer', 'http://localhost:8080/geoserver/isagro/wms');

// Retrieve the 'showMap' parameter with a default value
const showMap = useConfigParam('showMap', true);

Benefits

  • Flexibility: Enables dynamic configurations based on environment variables and URLs.
  • Simplicity: Reduces complexity in configuration management.
  • Convenience: Easy integration with React projects using React Router.

Installation

Add the repository to your project with:

npm install react-use-config

Learn More

For additional details and a live preview of this project, visit the React Use Config GitHub Page.


Contributing

We welcome contributions! Follow these steps:

  1. Fork the project.
  2. Create a branch for your feature/bugfix (git checkout -b my-feature).
  3. Commit your changes (git commit -m 'My new feature').
  4. Push to the branch (git push origin my-feature).
  5. Open a pull request.

License

MIT


🚀 Built with ❤️ by Ricardo Malnati and the amazing open-source community!

Package Sidebar

Install

npm i react-use-config

Weekly Downloads

0

Version

3.0.2

License

MIT

Unpacked Size

8.52 kB

Total Files

7

Last publish

Collaborators

  • ricardomalnati