UNPKG

react-route-hook

Version:

A simple React Component for adding onEnter and onChange Hooks to the Route Component of react-router v4

29 lines (24 loc) 610 B
import React from 'react'; import PropTypes from 'prop-types'; import RouteHook from '../src/index'; export default class Search extends React.Component { componentDidMount() { this.props.history.push('/search?query=1'); } render() { return ( <RouteHook path="/search" render={() => null} onEnter={this.props.onEnter} onChange={this.props.onChange} /> ); } } Search.propTypes = { history: PropTypes.shape({ push: PropTypes.func, }).isRequired, onChange: PropTypes.func, onEnter: PropTypes.func, }; Search.defaultProps = { onEnter: () => {}, onChange: () => {}, };