Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive search example #13

Open
unoriginalscreenname opened this issue Dec 18, 2017 · 4 comments
Open

Reactive search example #13

unoriginalscreenname opened this issue Dec 18, 2017 · 4 comments

Comments

@unoriginalscreenname
Copy link

How would i properly use withQuery to create a component that can search a collection?

Let's say i have a PostList component which i am wrapping reactively withQuery. I'd like to have an input filed which I would pass as a search filter on the query. but i'm not sure how i would do this? How do you alter the query and have it update the component internally, without passing in props?

class PostList extends Component {
search(query, e){
let regex = new RegExp(e.target.value, 'i');
[do something with query]
query.params.filters = {
name:regex
}
}
render(){
<Input type={"text"} onChange={this.search.bind(this, this.props.query)}/>
}
}

const Container = withQuery((props) => {
return getPostLists.clone();
}, {reactive: true})(PostList);

@danilomiranda
Copy link

Hey @ericmcgregor I have the same issue, do you found the solution?

@danilomiranda
Copy link

@theodorDiaconu some help here?

@danilomiranda
Copy link

@bhunjadi
Copy link
Contributor

bhunjadi commented Feb 2, 2018

@danilomiranda @ericmcgregor
The only way I found to do that is to wrap the query container with component that renders search input (WrapperComponent in this example).

e.g.

class DataRenderingComponent extends Component {
  render() {
    const {data} = this.props;
    // render query data
}


class WrapperComponent extends Component {
  constructor(props) {
    super(props);

    this.QueryContainer = withQuery((props) => {
      const queryParams = {}; // extract params from props
      this.query = someQuery.clone(queryParams);
      return this.query;
    }, {reactive: true})(DataRenderingComponent);
  }

   render() {
     const queryProps = {search: this.state.search};
     return (<div>
       <QueryContainer {...queryProps} />
       <Input type={"text"} onChange={(event) => this.setState({search: event.target.value})}/>
      </div>);
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants