Created
February 8, 2017 15:01
-
-
Save DimitryDushkin/34b686e230e6fd55c791d0dcb53a2a51 to your computer and use it in GitHub Desktop.
Example of using react-router query utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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