1.4.1 • Published 4 years ago

with-react-query v1.4.1

Weekly downloads
21
License
MPL-2.0
Repository
github
Last release
4 years ago

with-react-query

A small wrapper of react-router parsing the query params from the location.search

CircleCI npm version

Basic usage with params

// Let's say you are at location '/foo?counter=1'
import React, { PureComponent } from 'react'
import { withRouter } from 'react-router-dom'
import withReactQuery from 'with-react-query'

class FooPage extends PureComponent {

  onIncrementCounter = () => {
    const { history, query } = this.props
    const { getSearchFromUpdate, params: { counter } } = query
    // navigate to /foo?counter=2
    history.push(getSearchFromUpdate({ counter: counter + 1 }))
  }

  render () {
    const { query } = this.props
    const { params: { counter } } = query
    return (
      <div>
        My counter is equal to {counter}
        <button onClick={this.onIncrementCounter}>
          Increment
        </button>
      </div>
    )
  }
}

export default withRouter(withReactQuery()(FooPage))

Usage for url in foreign language with translate

// Let's say you are at location '/foo/compteur=1'
import React, { PureComponent } from 'react'
import { withRouter } from 'react-router-dom'
import withReactQuery from 'with-react-query'

class FooPage extends PureComponent {

  onIncrementCounter = () => {
    const { history, query } = this.props
    const { counter } = query.getTranslatedParams()
    // navigate to /foo?compteur=2
    history.push(query.getSearchFromUpdate({ counter: counter + 1 }))
  }

  render () {
    const { query } = this.props
    const { counter } = query.getTranslatedParams()
    return (
      <div>
        My counter is equal to {counter}
        <button onClick={this.onIncrementCounter}>
          Increment
        </button>
      </div>
    )
  }
}

export default withRouter(withReactQuery({
  mapper: { compteur: "counter" }
})(FooPage))
1.2.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago