-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
useWindowDimensions
hook to replace most Dimensions
usage
Summary: Automatically provides and subscribes to dimension updates - super easy usage: ``` function MyComponent(props: Props) { const {width, height, scale, fontScale} = useWindowDimensions(); return <Text ... }; ``` Only window for now - it's what people want 99% of the time, so we'll just shovel out a pit of success for them... There are still cases where `Dimensions` is needed outside of React component render functions, like in GraphQL variables, so we need to keep the existing module. Reviewed By: zackargyle Differential Revision: D16525189 fbshipit-source-id: 0a049fb3be8d92888a8a69e3898d337b93422a09
- Loading branch information
1 parent
62591ac
commit 5ec382d
Showing
6 changed files
with
126 additions
and
239 deletions.
There are no files selected for viewing
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
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
Oops, something went wrong.
5ec382d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sahrens You’re calling forceUpdate() which is an empty setState() but I thought react don’t update when the state is the same? Anyway, if you committed it’s probably working
5ec382d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's opt-in via
PureComponent
,shouldComponentUpdate
,memo
, etc.5ec382d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better practice to update state anyway though - I'll update to make it clear.
5ec382d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I was talking specifically about the hook
useState
, I remember when react made the change so it won't trigger a new update when the value is the same.Made this quick codesandbox: https://codesandbox.io/embed/elegant-cori-0ixbx
PR: #25990
5ec382d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect at this place also the orientation info about the device