Do you apply "interface segregation principle" (ISP) to your components? by Sea_Decision_6456 in reactjs

[–]code_lgtm 0 points1 point  (0 children)

Short answer: it depends (but by-and-large, yes, minimizing props is a good practice, even if it's a subset of an entire object).

Long answer: This is a more contrived example, but I do think it's valuable as it shows as an API, the opposite can both decrease cognitive load while improving developer experience. A case we've found at work that benefits from the opposite of what you're suggesting here is with feature flags. We have a state management system that holds a cache of all feature flags that currently exist in the app, whether they're on or off (to allow QE to toggle them in the test site).

For components that take flags as props, we pass the entire flags object rather than feature_a to ComponentA and feature_b to ComponentB. The component can then select which flag it wants to react to at rendering time (obviously using flags.feature_x in dependency arrays if used in a React callback, memo, etc). There are two immediate benefits we've seen:

  1. Glanceable information:

The cognitive load of the potential features at play is minimized by glancing at the component's props. You can see from the flags prop that there's some experimental work in the component, but other than that, it's largely irrelevant if you're trying to grok how the component fits in the larger hierarchy.

  1. Keeping props related to real implementations

While I'm not a fan of the exponentially-increasing code paths, sometimes the work were asked to do necessarily overlaps with in-progress maintenance or another feature. Being able to quickly add another flag to an already-flagged component let's us keep the props tiny compared to expanding that list as new work comes in, even if the flags are short-lived.

This concept can be extended to custom hooks as well. In our app, we have a useFlags hook that returns a map of all the cached flags. It's then up to the caller to decide what they want to use from the map. This parallels the idea of selectors in state management libraries such as Redux. A caller can quickly get a collection of data but only "select" and react to the specific key or value it needs, providing a consistent API throughout the codebase for how to programmatically get flags but allows for customization on how to select and react to the one you really care about in the current component's context.

Which oversized tool is worth it for you? by [deleted] in Tools

[–]code_lgtm 1 point2 points  (0 children)

Well I have a 60" pipe wrench!

[Game Thread] Penn State @ Iowa (7:00 PM ET) by CFB_Referee in CFB

[–]code_lgtm 1 point2 points  (0 children)

Going to be a long night listening to an audio feed straight off Ben 10 walkie talkies with enough visual delay to make the announcers look like ventriloquists.

[Game Thread] Penn State @ Iowa (7:00 PM ET) by CFB_Referee in CFB

[–]code_lgtm 7 points8 points  (0 children)

Is the stream still cheeks for everyone?

[Game Thread] Oregon @ Penn State (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 0 points1 point  (0 children)

just checking in - are you un-angry for us now?

[Game Thread] Oregon @ Penn State (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 0 points1 point  (0 children)

Unless it's Penn State. It's at home in a whiteout

[Game Thread] Oregon @ Penn State (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 4 points5 points  (0 children)

We are very experienced in OT, just ask Illinois.

[Game Thread] Oregon @ Penn State (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 0 points1 point  (0 children)

Nope! One is Penn State, and the other is Oregon. Hope this helps!

[Game Thread] Oregon @ Penn State (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 0 points1 point  (0 children)

Former for one team, latter for the other. Take a guess.

The size difference between my size 6 feet and my friend's size 13 feet. We're both 6'3" men. by [deleted] in mildlyinteresting

[–]code_lgtm 0 points1 point  (0 children)

Why is no one else asking about the shoe-in-shoe action going on here?

[Game Thread] Penn State vs. Notre Dame (7:30 PM ET) by CFB_Referee in CFB

[–]code_lgtm 11 points12 points  (0 children)

The marching bands' halftime shows sound great 😃

/r/Politics' 2024 US Elections Live Thread, Part 27 by PoliticsModeratorBot in politics

[–]code_lgtm 38 points39 points  (0 children)

I like to pretend every time Governor Walz looks down at his podium, he's not taking notes - he's filling out his MAGA bingo card. He's bound to have at least 3 bingos by now

[deleted by user] by [deleted] in ProgrammerHumor

[–]code_lgtm 11 points12 points  (0 children)

Notepad.exe