Mike Cronin
1 min readOct 13, 2019

See this is why I love writing. Yea, my code is just straight up wrong. I had my wires crossed and never had anyone tell me.I was carrying over a JSX thing. With JSX, if you want something like:

onClick={doThing(something)} // bad, don't do this

That would run the function immediately on render, not on a click. You have to do:

onClick={() => doThing(stuff)}

And I accidentally carried that over to .then chains with promises. Excellent catch, I will correct my code so that others don’t pick up this incorrect code. That being said, could you explain why we need to wrap a function in a function:

const showSaveAlertFor = (milliseconds) => () => { 
setCurrentAlert(‘Saved!’);
...
// vs no nesting
const showSaveAlertFor = (milliseconds) => {
setCurrentAlert(‘Saved!’);
...

I just ran the non-nested version and it worked as expected, but it’s possible there are performance or side effect implications that I’m not aware of.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (1)

Write a response