Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimitryDushkin/34b686e230e6fd55c791d0dcb53a2a51 to your computer and use it in GitHub Desktop.
Save DimitryDushkin/34b686e230e6fd55c791d0dcb53a2a51 to your computer and use it in GitHub Desktop.
Example of using react-router query utils
import Modal from 'react-modal';
import { addQuery, removeQuery } from './utils-router.js';
const OPEN_MODAL_QUERY = 'openModal';
function SomeComponent({ location }) {
return <div>
<button onClick={ () => addQuery({ OPEN_MODAL_QUERY : 1 })}>Open modal</button>
<Modal
isOpen={ location.query[OPEN_MODAL_QUERY] }
onRequestClose={ () => removeQuery(OPEN_MODAL_QUERY) }>
<h1>Modal Content</h1>
</Modal>
</div>;
}
// inject "location" property from react-router
// to correct server-side rendering of opened modal
export default withRouter(SomeComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment