MCPcopy
hub / github.com/react-native-community/hooks

github.com/react-native-community/hooks @v100.1.0 sqlite

repository ↗ · DeepWiki ↗ · release v100.1.0 ↗
24 symbols 74 edges 23 files 0 documented · 0%
README

React Native Hooks

React Native Hooks

Version

React Native APIs turned into React Hooks allowing you to access asynchronous APIs directly in your functional components.

Note: You must use React Native >= 0.59.0

Installation with npm

npm install @react-native-community/hooks

Installation with yarn

yarn add @react-native-community/hooks

API

useAccessibilityInfo

import {useAccessibilityInfo} from '@react-native-community/hooks'

const {
  boldTextEnabled,
  screenReaderEnabled,
  reduceMotionEnabled, // requires RN60 or newer
  grayscaleEnabled, // requires RN60 or newer
  invertColorsEnabled, // requires RN60 or newer
  reduceTransparencyEnabled, // requires RN60 or newer
} = useAccessibilityInfo()

useAppState

AppState will change between one of 'active', 'background', or (iOS) 'inactive' when the app is closed or put into the background.

import {useAppState} from '@react-native-community/hooks'

const currentAppState = useAppState()

useBackHandler

import {useBackHandler} from '@react-native-community/hooks'

useBackHandler(() => {
  if (shouldBeHandledHere) {
    // handle it
    return true
  }
  // let the default thing happen
  return false
},[shouldBeHandledHere])

useImageDimensions

import {useImageDimensions} from '@react-native-community/hooks'

const source = require('./assets/yourImage.png')
// or
const source = {uri: 'https://your.image.URI'}

const {dimensions, loading, error} = useImageDimensions(source)

if (loading || error || !dimensions) {
  return null
}
const {width, height, aspectRatio} = dimensions

useKeyboard

import {useKeyboard} from '@react-native-community/hooks'

const keyboard = useKeyboard()

console.log('keyboard isKeyboardShow: ', keyboard.keyboardShown)
console.log('keyboard keyboardHeight: ', keyboard.keyboardHeight)

useInteractionManager

import {useInteractionManager} from '@react-native-community/hooks'

const interactionReady = useInteractionManager()

console.log('interaction ready: ', interactionReady)

useDeviceOrientation

import {useDeviceOrientation} from '@react-native-community/hooks'

const orientation = useDeviceOrientation()

console.log('orientation is:', orientation)

useLayout

import { useLayout } from '@react-native-community/hooks'

const { onLayout, ...layout } = useLayout()

console.log('layout: ', layout)

<View onLayout={onLayout} style={{width: 200, height: 200, marginTop: 30}} />

useRefresh

import {useRefresh} from '@react-native-community/hooks'

const fetch = () => {
  return new Promise((resolve) => setTimeout(resolve, 500))
}

const {isRefreshing, onRefresh} = useRefresh(fetch)

;<ScrollView
  refreshControl={
    <RefreshControl refreshing={isRefreshing} onRefresh={onRefresh} />
  }
/>

Thanks

We use Changesets for managing releases and versioning.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Pavlos Vinieratos 💻 🎨 📖 🚇 🚧 ⚠️ Melih 💻 📖 🚇 ⚠️ Jesse Katsumata 💻 📖 🚧 ⚠️ abhishek gupta 🐛 Zeljko 💻 Linus Unnebäck 💻 🚇 📖 ⚠️ Tony Xiao 💻
Ronaldo Lima 💻 Marius Reimer 💻 Nishith Patel 💻 jozn 📖 Andrew Lisowski 🚇 📦 🔧 💻 📖 faraz ahmad 📖 Nader Dabit 🤔
Dani Akash 💻 Dylan Vann 💻 Tihomir Valkanov 📖 Pierre Skowron 💻 Gamal Shaban 💻 📖 ⚠️ Greg-Bush 📖 💻 ⚠️ 🚇 Alan Kenyon 📖 💻
Thibault Maekelbergh ⚠️ 💻 Gertjan Reynaert ⚠️ 💻

Extension points exported contracts — how you extend this code

URISource (Interface)
(no doc)
src/useImageDimensions.ts
ImageDimensions (Interface)
(no doc)
src/useImageDimensions.ts
ImageDimensionsResult (Interface)
(no doc)
src/useImageDimensions.ts

Core symbols most depended-on inside this repo

useAccessibilityInfo
called by 18
src/useAccessibilityInfo.ts
useImageDimensions
called by 8
src/useImageDimensions.ts
useKeyboard
called by 6
src/useKeyboard.ts
useAccessibilityStateListener
called by 6
src/useAccessibilityInfo.ts
useBackHandler
called by 3
src/useBackHandler.ts
useLayout
called by 2
src/useLayout.ts
useAppState
called by 2
src/useAppState.ts
useInteractionManager
called by 2
src/useInteractionManager.ts

Shape

Function 21
Interface 3

Languages

TypeScript100%

Modules by API surface

src/useKeyboard.ts5 symbols
src/useImageDimensions.ts4 symbols
src/useRefresh.ts2 symbols
src/useAppState.ts2 symbols
src/useAccessibilityInfo.ts2 symbols
src/useRefresh.test.ts1 symbols
src/useLayout.ts1 symbols
src/useKeyboard.test.ts1 symbols
src/useInteractionManager.ts1 symbols
src/useInteractionManager.test.ts1 symbols
src/useDeviceOrientation.ts1 symbols
src/useBackHandler.ts1 symbols

Dependencies from manifests, versioned

@changesets/cli2.28.1 · 1×
@jest/globals29.7.0 · 1×
@testing-library/react-native13.0.1 · 1×
@types/jest29.5.14 · 1×
@types/react18.3.18 · 1×
eslint9.20.1 · 1×
jest29.7.0 · 1×
prettier3.5.1 · 1×
react18.3.1 · 1×
react-native0.78.0 · 1×

For agents

$ claude mcp add hooks \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact