
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-native-app-state
Advanced tools
react-native-app-state
is a declarative way to use react-native's AppState.
Internally it uses the new React 16.3 Context API.
I think you got it. It's definitely easier than:
Because this library uses the new React 16.3 Context API, you need at least React 16.3.
$ yarn add react-native-app-state
$ npm install react-native-app-state --save
See the example project under example/
import AppState from 'react-native-app-state';
class App extends React.PureComponent {
onAppStateChange = (appState, prevAppState) => {
console.log(this.constructor.name, 'onAppStateChange()', prevAppState, '=>', appState);
// E.g. output: "App onAppStateChange() background => active"
};
render() {
return (
<View>
<AppState onChange={this.onAppStateChange}>
{({ appState }) => (
<View>
<Text style={styles.text}>App state: {appState}</Text>
</View>
)}
</AppState>
{/* ------ OR ------ */}
<AppState onChange={this.onAppStateChange}>
<AppState.Active>
<Text>App is active</Text>
</AppState.Active>
<AppState.Inactive>
<Text>App is inactive</Text>
</AppState.Inactive>
<AppState.Background>
<Text>App is in background</Text>
</AppState.Background>
</AppState>
</View>
);
}
}
<AppState.Active>
, <AppState.Inactive>
, <AppState.Background>
<AppState.Foreground>
alias for <AppState.Active>
and <AppState.Inactive>
<AppState>{({ appState }) => (<View />)}</AppState>
FAQs
A declarative way to use react-native's AppState
We found that react-native-app-state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.