- Fixed initial state context key, making it a function rather than object, allowing components mounting after first render to pull current media query match state before rendering.
- Set
queries
andonChange
default arg tonull
to fix argument validation.
- Add a changelog.
-
Provide initial match state to children of
wMQ
andMWRP
.- Previously, the
<Provider>
component would not provide the initial match state of the user'squeries
(passed to the<Provider>
). ThewMQ
andMQRP
components only subscribe to updates incomponentDidMount
, as side-effects (and subscriptions) in theconstructor
should be avoided. This is problematic if the user wishes to, for example, dynamically route (possibly with redirects) depending on the device width, which may result in undesireable redirects on first render. - To remedy this, the
<Provider>
now sets a second childcontext
key:mediaQueriesInitialState
, whichMQRP
andwMQ
will provide to child components initially.
- Previously, the
-
Better namespacing of context keys to avoid collisions.
-
Add fourth named argument to
MQLManager
constructor fn:parentMounted
which is aBoolean
. IfparentMounted
is set to false, MQLManager will not attach a listener to its Media Query Lists until you call theaddListeners()
method, ideally fromcomponentDidMount
. CallremoveListeners()
fromcomponentWillUnmount
if the component hosting MQLManager unmounts. -
Add
addListeners
andremoveListeners
methods as described above. -
Added an internal method to construct a mock MQL returning
true
as the.matches
property for all queries, whentypeof window !== 'object'
(ie server-side rendering).
- Initial tests ensuring
queries
match state returnstrue
when SSRing.
- Updates reflecting the above changes.
- Info on getting initial state from MQLManager when not using Provider.
- Added troubleshooting.