React: get child component data from parent

Viewed 1571

I have a react component like below:

<Parent>
    <Child />
    <button type="button" />
</Parent>

<Child /> has a input[type="file"] form control in it.

when I click the button in <Parent />, I want to upload the file in <Child /> with ajax,

how can I access the input[type="file"] inside <Child />?

I tried using refs

<Parent>
    <Child ref="child"/>
    <button type="button" />
</Parent>

so that I can access the input by writing

this.refs.child.refs.file

but I do not think it's the best practice....

2 Answers
Related