Create feature flag in React | Atlassian machine coding question

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 31

  • @sahilsatishkumar
    @sahilsatishkumar ปีที่แล้ว +9

    The actual question they ask is not around React. It's a plain JS library that they are looking for.

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      You can use framework of your choice

    • @javascriptworld3443
      @javascriptworld3443 ปีที่แล้ว +5

      @@Learnersbucket But it is JS coding round in Atlassian, also this utility should be in JS so that it can extend to various layer, not just UI layer.

  • @ganeshkhirwadkar4127
    @ganeshkhirwadkar4127 ปีที่แล้ว +2

    Bahut sahi Prashant bhai !

  • @riturajsingh2556
    @riturajsingh2556 7 หลายเดือนก่อน +1

    Appreciate the solution. I understand the point of using context to make the feature flags available throughout the app. But I see two drawbacks with this.
    1. the api call to fetch the feature flags will happen on any page the user lands on directly, irrespective of whether we are using a feature flag or not on that particular page.
    2. imagine a scenario when a user is on a website, a feature flag is toggled from the admin panel. How do we achieve displaying the new feature to the user.
    Instead I would suggest using a HOC or a custom useFeatureFlag hook. We can wrap only those components where we need the feature flag api call to happen. Or we can call the hook in files where we need feature-flags to be implemented. This will make sure that the features are fresh enough and the hook can be easily extracted into a separate npm package altogether. Thoughts ?

    • @Learnersbucket
      @Learnersbucket  7 หลายเดือนก่อน +1

      Feature flags are bootstrap data that has to be loaded on the initial load.
      It's a simple tradeoff that is agreeable to avoid any security leaks

  • @shubhamkumar-jo2vo
    @shubhamkumar-jo2vo ปีที่แล้ว +2

    share across the different app -> we need to use cookies and set the domain properly.

  • @kshitijvengurlekar1192
    @kshitijvengurlekar1192 ปีที่แล้ว +2

    How about using something like react-query to cache which features and enabled/disabled?

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      Works

    • @kshitijvengurlekar1192
      @kshitijvengurlekar1192 ปีที่แล้ว +1

      @@Learnersbucket Exactly, a more complex version of this problem would be where we have a RBAC and specific action elements are visible / disabled / hidden for users with specific roles

  • @anirudhcodes
    @anirudhcodes ปีที่แล้ว +2

    Can we load the variables via reverse proxy such as nginx as an alternative? Where in the feature flags get decided on the deployed frontend instance envs

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว +1

      On the server-side rendering, you can pull from environment variables. On the client side rendering you have to pull through network calls

    • @anirudhcodes
      @anirudhcodes ปีที่แล้ว +1

      ​@@Learnersbucket ok, for one of the FE apps that was built in angular we used this way to load app-config everytime there is complete page reload and in that nginx api we were getting the config values. So wanted to check if that approach is correct or not to answer in interview

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      @@anirudhcodes not able to understand. Nginx is an Application server, not an API provider.

  • @nallaparajuamareshvarma8471
    @nallaparajuamareshvarma8471 ปีที่แล้ว +1

    can anyone tell how to share the feature flag with different apps

  • @themeniacs7376
    @themeniacs7376 ปีที่แล้ว +2

    Great video man

  • @rahul191jain
    @rahul191jain ปีที่แล้ว +3

    To share it with other apps, only solution I guess can be create lib and share it. If you know any other solution please share

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      Yup built an sdk or library

    • @guptaankit2791
      @guptaankit2791 6 หลายเดือนก่อน +1

      @@Learnersbucket We can expose it as a micro-frontend app as well to share with other apps.

    • @Learnersbucket
      @Learnersbucket  6 หลายเดือนก่อน +1

      @@guptaankit2791 microfrontend is an architecture, not a way to share data.
      It should not be over used

  • @killadasatyaaditya5960
    @killadasatyaaditya5960 7 หลายเดือนก่อน +1

    The sandbox link is not opening

  • @Shubham-yc6nz
    @Shubham-yc6nz 8 หลายเดือนก่อน +1

    Why did you used context? Was the question about it. Can we just do this instead?
    ```
    const Feature = ({ feature, children }) => {
    const [features, setFeatures] = useState({
    default: true,
    pro: true,
    enterprise: false,
    });
    useEffect(() => {
    // fetch & set feature from an backend API
    }, []);
    return features[feature] ? {children} : null;
    };
    export default function App() {
    return (

    Free Plan
    Pro Plan
    Enterprise Plan

    );
    }
    ```

    • @Learnersbucket
      @Learnersbucket  8 หลายเดือนก่อน +1

      Feature flags should be available throught out the app, thus context

  • @vijaynavale3919
    @vijaynavale3919 ปีที่แล้ว +1

    Bhai vo aapke `js interview guide` me custom promise ka solution he, vo aap ne khud se likha tha ki kahi se refer kiya tha ?

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      Referred hai

    • @vijaynavale3919
      @vijaynavale3919 ปีที่แล้ว +2

      ​@@LearnersbucketAchaa, but vo solution badiya he, kya soch ke likha he maza aagaya dekh ke🙌💯

    • @Learnersbucket
      @Learnersbucket  ปีที่แล้ว

      @@vijaynavale3919 thanks 😊

  • @mirage4731
    @mirage4731 3 หลายเดือนก่อน +1

    Is this really asked for SDE1 role ? I am scared

    • @Learnersbucket
      @Learnersbucket  3 หลายเดือนก่อน

      @@mirage4731 no sde2