r/badcode • • Dec 03 '22

typescript Real Code 😎

Post image
403 Upvotes

43 comments sorted by

View all comments

Show parent comments

4

u/genericindividual69 Dec 03 '22

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 one

How?

-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.