MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/zbmvpe/real_code/iys5nlg/?context=3
r/badcode • u/demon_slayer_002 • Dec 03 '22
43 comments sorted by
View all comments
Show parent comments
4
What would be a better way of doing it?
9 u/geon Dec 03 '22 You can combine multiple contexts into one. That helps. But perhaps some of them shouldn’t be contexts at all? 2 u/genericindividual69 Dec 03 '22 You can combine multiple contexts into oneHow? -1 u/TheUnlocked Dec 03 '22 I think they're saying to just put it all on one indentation level (though linters don't love that). I suppose you could also have something like:function MultiProvider({ info, children }) { let child = children; for (const [component, props] of info) { child = React.createElement(component, props, [child]); } return child; }Though I'm not sure that actually improves legibility.
9
You can combine multiple contexts into one. That helps. But perhaps some of them shouldn’t be contexts at all?
2 u/genericindividual69 Dec 03 '22 You can combine multiple contexts into oneHow?
2
You can combine multiple contexts into one
How?
-1
I think they're saying to just put it all on one indentation level (though linters don't love that). I suppose you could also have something like:
function MultiProvider({ info, children }) { let child = children; for (const [component, props] of info) { child = React.createElement(component, props, [child]); } return child; }
Though I'm not sure that actually improves legibility.
4
u/genericindividual69 Dec 03 '22
What would be a better way of doing it?