appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 470 forks source link

clarifying setQuery prop in ReactiveComponent's child #288

Closed bolekro closed 6 years ago

bolekro commented 6 years ago

Issue Type: Question

Description: I just had a clarifying question on how the setQuery prop in ReactiveComponent's child is supposed work. I tried to build something similar to https://opensource.appbase.io/reactive-manual/native/advanced/reactivecomponent.html, but I am getting props.setQuery undefinied errror.

My question therefore is how the setQuery is supposed to work in the ReactoveComponent's child, as we never pass to it - in the example to the ColorPickerWrapper? The example specifies we only have to:

In our current example, we would simply have to call this.props.setQuery()

If anyone had success setting up custom ReactiveComponents and understands how it works please clarify it for me.

BTW, thanks for this project.

Screenshots: N/A

Minimal reproduction of the problem with instructions: N/A

Reactivesearch version: native 0.6.2

Browser: N/A

Anything else: N/A

metagrover commented 6 years ago

We internally expose setQuery as a prop to all the children passed to the ReactiveComponent. You can check this snack to see how to use the setQuery method with the ReactiveComponent.

bolekro commented 6 years ago

That is what I figured from the ReactiveComponents.js src file. Do you have any idea why my child component is not seeing it (getting undefined error for props.setQuery)?

My code snippet:

 <ReactiveComponent 
       componentId="id"  
       defaultQuery={() => ({  
                    query: {  
                                match_all: {},  
                     }  
                  })}  
      >  
     <ChildComponent />  
</ReactiveComponent>
metagrover commented 6 years ago

I'm not too sure. Can you create a snack snippet replicating your issue here?

PS: Make sure that your ReactiveComponent is wrapped inside a ReactiveBase component.

bolekro commented 6 years ago

Thank you for your help, turned out my callback function did not have proper binding. After correction the ReactiveComponent works great.