1

I have two Components (Preview and FileInput) within single Provider. I want to trigger file field when clicking on preview image.

My code looks like (simplified):

 <Provider>
   <Form>
     <Preview><ImagePlaceholder onClick={}/></Preview>
     <FileUploader><input type="file"/><FileUploader/>
   </Form>
 </Propvider>

What is best way in react-redux flow to trigger one Component from another?

I think about flag in store. Something like "shouldClickFileInput". So on click on placeholder i would set it true, and on click on input - false.

2 Answers 2

1

If you need to perform the same action from different controls, just do it:

<Provider>
   <Form>
      <Preview><ImagePlaceholder onClick={this.handleClick}/></Preview>
      <input type="file" onClick={this.handleClick}/>
   </Form>
</Propvider>

I guess that you have some upload form, which should show file select dialog on click on different items. It would be better to render several input[type=file] for each clickable area. And then you can sync selected value through the store, not the fact of the click event.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This is just what i need.
0

If I'm following your question, I think the best way is to setup a method for the onClick event and have that function fire whatever 'action' functions you would like to trigger. Something along the lines of:

handleClick(){
  action1();
  action2();
}

<Provider>
  <Form>
    <Preview><ImagePlaceholder onClick={this.handleClick}/></Preview>
    <FileUploader><input type="file"/><FileUploader/>
  </Form>
</Propvider>

Does that rational make sense?

1 Comment

Case is, that Preview and FileUploader is connected to store components. So, to achieve this way i need to transfer props all the way through children components. As i see it - it is not a good way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.