Skip to content

Provides a hook called useConfigParam to retrieve configuration parameters with priority: URL query, environment variables, and default value. It simplifies configuration management, enabling flexibility and adaptability across different environments and scenarios.

License

Notifications You must be signed in to change notification settings

Malnati/react-use-config

Repository files navigation

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!

About

Provides a hook called useConfigParam to retrieve configuration parameters with priority: URL query, environment variables, and default value. It simplifies configuration management, enabling flexibility and adaptability across different environments and scenarios.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published