2

Short answer: You can include setExpanded in the dependency array. Long answer: The function passed to useEffect will fire only when at least one of the dependencies changes: useEffect(() => { // runs // - on mount // - on every render }) useEffect(() => { // runs // - on mount only }, []) useEffect(() => { // runs // - on mount ...


2

A few things stood out to me: You can extract out the implementation details behind where the token exists. Not a huge deal, but personally I would do this: const setAuthToken = (token) => document.querySelector('meta[name=csrf-token]').setAttribute('content', token) const getAuthToken = () =>document.querySelector('meta[name=csrf-token]')....


2

Just some quick/general thoughts here, not really an in-depth analysis. Regarding performance, it's imperative to use devtools performance profiler (or its simpler version "JavaScript profiler" in Chrome) and optionally other more specialized tools for node.js, etc. Otherwise you'll get a rehashing of the well-known practices which most likely have little ...


2

It seems this could be simplified with a small lookup table and then concatenating strings. Using a table as simple as: const lookup = { blue: 'b', green: 'f', purple: 'g', yellow: 'p' }; we can then lookup the color values and concatenate them together. Combined with a simple check to make sure the color is valid and the 2 colors aren't the same, ...


2

Usually if I have a big list of mappings from one string to another, that is likely to be later enhanced on, I use a generic mapping method, that is fed a static mapping constant. So the first iteration would be something like: type ExpectedMimeTypes = 'image/png' | 'image/jpg' | 'image/jpeg' | 'application/pdf' | never; type ExpectedMagicOutput ...


1

I wouldn't say the code is difficult to follow but I do have some suggestions. The first thing I notice is that some variables are declared with let. Many of those variables never get re-assigned. It is wise to use const for any value that shouldn't get re-assigned - even if it isn't a constant. This helps avoid accidental re-assignment. The variables ...


1

You have the right idea, and your function almost works, but your code is only checking that ( is balanced with ), and [ is balanced with ]. So it will handle cases like aaa(bbb[ccc]ddd)eee correctly. But it will also accept aaa(bbb[ccc)ddd]eee, and that is wrong. You should only have a single stack, and you should push all the opening brackets onto it. ...


Only top voted, non community-wiki answers of a minimum length are eligible