Skip to content

Commit dd0be29

Browse files
authored
Quality of Life Updates (#17)
* Update * Revert * A lot * Fix
1 parent 714f680 commit dd0be29

File tree

11 files changed

+28827
-28120
lines changed

11 files changed

+28827
-28120
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @paulomfj @maikelvdzande
1+
* @paulomfj @maikelvdzande @maartenbruggink

.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("@buildinams/lint/prettier");

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ const MyComponent = () => {
4646

4747
## Using 'defaultValue'
4848

49-
If you want to provide a default value for the initial render (and in server), you can pass it as `defaultValue` within the _optional_ config object.
49+
If you want to provide a default value for the initial render (and in server), you can pass it as `defaultValue` within the _optional_ config object. This accepts `boolean`, `undefined`, or `null`. For example:
5050

5151
```tsx
5252
import useMatchMedia from "@buildinams/use-match-media";
5353

5454
const MyComponent = () => {
55-
const isMobile = useMatchMedia("(max-width: 768px)", { defaultValue: true });
55+
const isSmall = useMatchMedia("(max-width: 768px)", { defaultValue: true });
5656
...
5757
};
5858
```
5959

6060
Couple things to **note**:
6161

6262
- The default value will only be used on the initial render and SSR. By the second render, the hook will use the actual value matched.
63-
- If left `undefined`, the default value will be `false`.
63+
- If theres already a match for the query, the hook will use the actual value matched instead of the default value.
64+
- If left blank, the default value will be `false`.
6465

6566
## Conditionally Listening to Events
6667

@@ -72,11 +73,26 @@ import useMatchMedia from "@buildinams/use-match-media";
7273
const MyComponent = () => {
7374
const [isEnabled, setIsEnabled] = useState(false);
7475

75-
const isMobile = useMatchMedia("(max-width: 768px)", { isEnabled });
76+
const isSmall = useMatchMedia("(max-width: 768px)", { isEnabled });
7677
...
7778
};
7879
```
7980

81+
## Using Layout Effect
82+
83+
By default, the hook will use `useEffect` to listen to events. However, you can use `useLayoutEffect` instead by passing `layoutEffect` in the config object. For example:
84+
85+
```tsx
86+
import useMatchMedia from "@buildinams/use-match-media";
87+
88+
const MyComponent = () => {
89+
const isSmall = useMatchMedia("(max-width: 768px)", { layoutEffect: true });
90+
...
91+
};
92+
```
93+
94+
This is SSR safe, and will only use `useLayoutEffect` on the client.
95+
8096
## Requirements
8197

8298
This library requires a minimum React version of `17.0.0`.

jest.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Config } from "@jest/types";
22

33
const config: Config.InitialOptions = {
4-
verbose: true,
5-
testEnvironment: "jsdom",
6-
roots: ["<rootDir>/tests"],
4+
verbose: true,
5+
testEnvironment: "jsdom",
6+
roots: ["<rootDir>/tests"],
77
};
88

99
export default config;

0 commit comments

Comments
 (0)