DEV Community

Discussion on: Implementing feature toggles for a React App using Webpack

Collapse
 
ramsunvtech profile image
Venkat.R • Edited

Avraam, it was written nicely on the feature toggle. Lets take a example, instead of Feature toggle take it as Country Toggles.

Sample Use Case 1, where we need to list the city
USA
Show City Name as null for state 1 and state 2 and else return city
INDIA.
Show city details as always
BELGIUM
Show city with --City--

Below is the code samples, whats your take on this

const {
  cityName,
  cityKey
} = country({
 US: async () => {
  const response = await apiCall();
  if (state1 || state2) {
     return null;
  }

  return {
     cityName: response.city,
     cityKey: response.cityKey,
  };
 },
IN: async () => {
  const response = await apiCall();
    return {
     cityName: response.city,
     cityKey: response.cityKey,
  };
},
BE: async () => {
  const response = await apiCall();
    return {
     cityName: `--${response.city}`,
     cityKey: response.cityKey,
  };
});
Enter fullscreen mode Exit fullscreen mode