Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Add withIsConnected higher order component #56966

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/compose/src/higher-order/with-is-connected/README.md
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 )
```
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;
1 change: 1 addition & 0 deletions packages/compose/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { default as withInstanceId } from './higher-order/with-instance-id';
export { default as withSafeTimeout } from './higher-order/with-safe-timeout';
export { default as withState } from './higher-order/with-state';
export { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';
export { default as withIsConnected } from './higher-order/with-is-connected';

// Hooks.
export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';
Expand Down
Loading