ill read it later. I dont remember exactly what you were doing in your code before, I just glanced at it, the problem is codepen.io, had you used git we could see what it was before and you could ask a more specific question about a specific part of the code.
Im not sure what you mean, perhaps you could make a new post with code sample to illustrate your specific question. What I was trying to say before, at least what I remember from your code was you had alot of things you were doing and at the top of multiple functions id see something like :
setState('some_value_only_needed_once')
You have to remember setting state is not synchronous, what that means is your code was looking something like:
handleSomeKeyClick=()=>{
setState('some_value_only_needed_once')
// do some other stuff
}
handleSomeOtherAction=()=>{
setState('some_value_only_needed_once')
// do some other stuff
}
I think its not going to wait for setState to finish before it advances to do some other stuff yes? above I just gave two examples, but if I recall correctly you also had been setting state to the same thing in alot of places.
I mean you try this function:
const [count, setCount] = useState(0)
someAction=>{
setState(count+1)
setState(count+1)
}
It wont work. try it yourself.
Maybe they expecting to see some value at some point in time and its not what you think it is. We would have to look at the old code and ask someone that is more experienced with the tests I cant say exactly. If you can make a new post showing a specific code with a specific question that would help.
just because it appears that it works doesnt mean its really working. What if you have to do something immediately with some value? yet instead you are setting the state all over the place. There is a concept TDD, I didnt have the time to research it yet, it is more advanced.
Yes that is good, just to recap If I recall correctly I believe you were also do something like this in your code (though you said you fixed it) :
render (
{someProp && <ComponentA prop={someValue} prop2={someValue2}/> }
{!someProp && <ComponentA prop={someValue} prop2={someValue3}/> }
)
so I mean instead of doing this
{someProp?<button prop={something}/>:<button prop={somethingElse}}
You will rather extract the button as your own custom component and only need to write it once in the render. I also make this same mistake often. I think it has to do with DRY (dont repeat) and preventing errors that can happen from copying and pasting. and keeping your code smaller rather than larger.
Im not an expert in react so youll have to verify that what I say is correct.