-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Add withIsConnected higher order component (#56966)
* Add withIsConnected HOC * fix: Destructure isConnected value from useIsConnected Hook The previous value was always `undefined`. * docs: Avoid permalink in documentation Permalinks would likely referenced outdated code at some point. Documentation is generally expected to be up-to-date. --------- Co-authored-by: David Calhoun <github@davidcalhoun.me>
- Loading branch information
1 parent
b592ba9
commit 863bc33
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/compose/src/higher-order/with-is-connected/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# withIsConnected | ||
|
||
`withIsConnected` provides a true/false mobile connectivity status based on the `useIsConnected` hook found in the [bridge](https://github.com/WordPress/gutenberg/blob/trunk/packages/react-native-bridge/index.js). | ||
|
||
## Usage | ||
```jsx | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withIsConnected } from '@wordpress/compose'; | ||
|
||
export class MyComponent extends Component { | ||
if ( this.props.isConnected !== true ) { | ||
console.log( 'You are currently offline.' ) | ||
} | ||
} | ||
|
||
export default withIsConnected( MyComponent ) | ||
``` |
18 changes: 18 additions & 0 deletions
18
packages/compose/src/higher-order/with-is-connected/index.native.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useIsConnected } from '@wordpress/react-native-bridge'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createHigherOrderComponent } from '../../utils/create-higher-order-component'; | ||
|
||
const withIsConnected = createHigherOrderComponent( ( WrappedComponent ) => { | ||
return ( props ) => { | ||
const { isConnected } = useIsConnected(); | ||
return <WrappedComponent { ...props } isConnected={ isConnected } />; | ||
}; | ||
}, 'withIsConnected' ); | ||
|
||
export default withIsConnected; |
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
863bc33
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.
Flaky tests detected in 863bc33.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7201027783
📝 Reported issues:
/test/e2e/specs/site-editor/navigation-editor.spec.js
/test/e2e/specs/site-editor/font-library.spec.js