I'm using react-responsive
to get media queries and I want to have one component state being shared across screen sizes, but using different wrappers.
Example:
import MediaQuery from 'react-responsive';
import ReactSwipe from 'react-swipe';
const Desktop = props => <MediaQuery {...props} minWidth={992} />;
const Tablet = props => <MediaQuery {...props} minWidth={768} maxWidth={991} />;
const Mobile = props => <MediaQuery {...props} maxWidth={767} />;
export class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Desktop>
<SignUpForm />
</Desktop>
<Tablet>
<SignUpForm />
</Tablet>
<Mobile>
<ReactSwipe>
<SignUpForm />
</ReactSwipe>
</Mobile>
</div>
);
}
}
In this example, I want to use another component <ReactSwipe>
to encapsulate <SignUpForm />
. The above works, but it's creating 3 instances of SignUpForm
... if you resize the browser and hit a breakpoint any form data you have filled out already will be lost as the new instance of SignUpForm
loads. How do I change this to use media queries but one instance of <SignUpForm />
.