I have this situation in my app: https://codesandbox.io/s/14mq9969j3
My goal is to be able to focus on input inside GrandChildInput
component by clicking on div in ChildInput
. However, when ChildInput
gets rendered, the value of this.childRef.current
is null
, and it remains so until I manually focus on input by clicking into it. After that, the value of current
is being assigned.
You can track this transformation in the console. The this.childRef.current
log appears once, but its value changes after manually focusing on input by clicking on it.
My end goal is to have the StyledGrandChildInput work this way, but as an intermediary step, I am trying to make the unstyled component work. I am able to achieve this result (with unstyled component) in my local project with:
- React 16.4.2
- Styled-Components 3.4.2
But when it comes to working in CodeSandbox with the versions that are installed in the project through the link above, for some reason even focusing on non-styled GrandChildInput component does not work.
How can I make the app focus on GrandChildInput component when I click on div
of ChildInput?