Use with a feature toggle
Feature toggles are an essential part of modern front-end applications, allowing you to control the activation and deactivation of features dynamically. This guide will demonstrate how to set up and use feature toggles with app-compose
.
Example
Independent Feature Toggle
In this example, the feature toggle does not depend on any external data and is self-contained.
Explanation:
fetchToggles
: Fetches the feature toggles and returns an object indicating whether each feature is enabled or disabled.featureToggle
: A container that fetches the toggles. The data is made available via itsapi
.referral
: A container that depends onfeatureToggle
. It checks if thereferral
feature is enabled using theenable
method. If the feature is not enabled, thereferral
container will not start.
With External Dependency
In this scenario, the feature toggle logic depends on external data, such as a user ID.
Explanation:
fetchUser
: Fetches the user information, such as the user ID.userEntity
: A container that provides user data via itsapi
.featureToggle
: This container depends onuserEntity
to get the user ID. It then fetches the feature toggles based on this ID.referral
: A container that depends onfeatureToggle
and only starts if thereferral
feature is enabled for the current user.
Conclusion
Using app-compose
, you can easily manage feature toggles and their dependencies. Whether the feature toggle is independent or depends on external data, this approach ensures clean and maintainable code.