Skip to content

Commit

Permalink
fix: add guide for migration from useBreakpoint to useMediaQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
mg901 committed May 23, 2023
1 parent b18d397 commit 3beb3d3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ const App = () => (

## Migration from v11

### Theme

The `createTheme` function has been replaced with `createStyledBreakpointsTheme`.

```diff
Expand All @@ -222,6 +224,8 @@ The `createTheme` function has been replaced with `createStyledBreakpointsTheme`
+ const theme = createStyledBreakpointsTheme();
```

### Media Queries

Additionally, the functions `up`, `down`, `between`, and `only` have been moved to the theme object. This means that you no longer need to import them individually each time you want to use them.

```diff
Expand All @@ -240,6 +244,33 @@ Additionally, the functions `up`, `down`, `between`, and `only` have been moved
`
```

### Hooks

```diff
- import { up } from 'styled-breakpoints';
- import { useBreakpoint } from 'styled-breakpoints/react-styled';

or

- import { up } from 'styled-breakpoints';
- import { useBreakpoint } from 'styled-breakpoints/react-emotion';

- const Example = () => {
- const isMd = useBreakpoint(only('md'));
-
- return <Layout>{isMd && </Box>}</Layout>
- }

+ import { useMediaQuery } from 'styled-breakpoints/use-media-query';

+ const Example = () => {
+ const theme = useTheme();
+ const isMd = useMediaQuery(theme.breakpoints.only('md'));
+
+ return <Layout>{isMd && </Box>}</Layout>
+ }
```

## Core concepts

- **Breakpoints act as the fundamental elements of responsive design**. They enable you to control when your layout can adapt to a specific viewport or device size.
Expand Down

0 comments on commit 3beb3d3

Please sign in to comment.