React Native
Core, every adapter and the timers package run in React Native unchanged. Stores, async strategies, machines and bindings don’t depend on the DOM. The one difference is how actions read input: React Native callbacks pass values, not DOM events.
Install
Section titled “Install”npx expo install @input-actions/coreMetro loads the packages with no configuration on React Native 0.79 or later (Expo SDK 53 or later), where it reads a package’s exports map by default. On older versions, turn that on in metro.config.js:
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);config.resolver.unstable_enablePackageExports = true;module.exports = config;The 'use client' directives in core are for Next.js; Metro ignores them.
Read callback values with event/arg
Section titled “Read callback values with event/arg”On the web, onChange receives an event and actions read event/target.value. React Native’s TextInput has onChangeText(text) and Switch has onValueChange(value), which pass the value itself. Read it with event/arg, or event/arg.N for the Nth argument:
import { Switch, Text, TextInput, View } from 'react-native';import { useLocalActions, save } from '@input-actions/core';
function Profile() { const { state, actions } = useLocalActions({ name: '', newsletter: false });
return ( <View> <TextInput value={state.name} onChangeText={actions(save(['name'], 'event/arg'))} /> <Switch value={state.newsletter} onValueChange={actions(save(['newsletter'], 'event/arg'))} /> <Text>{state.name}</Text> </View> );}The same works in bindings and async actions: asyncDebounce('search', 'search', 300, 'event/arg') passes the typed text to the handler.
Web-only placeholders and helpers
Section titled “Web-only placeholders and helpers”These read fields that only DOM events have. In React Native they give undefined, or do nothing:
- Placeholders:
event/target.*(value,checked,selectedIndex,files,dataset),event/key,event/keyCode,event/clientXandevent/clientY. - Helpers built on them:
saveInput,saveCheckbox,saveFiles,validateOnBlur,autoSaveandsearchAsYouType. Write the tuple withevent/arginstead, for examplesave(path, 'event/arg')in place ofsaveInput(path). preventDefault()andstopPropagation()have no effect.
Testing with jest-expo
Section titled “Testing with jest-expo”The packages are ES modules only, and jest-expo doesn’t transform node_modules by default. Add @input-actions to the packages it transforms:
"jest": { "preset": "jest-expo", "transformIgnorePatterns": [ "node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@input-actions/.*))" ]}Then test with React Native Testing Library:
import { fireEvent, render, screen } from '@testing-library/react-native';
test('saves the name', async () => { await render(<Profile />); await fireEvent.changeText(screen.getByDisplayValue(''), 'walter'); expect(screen.getByText('walter')).toBeTruthy();});What’s tested
Section titled “What’s tested”Every change runs a React Native consumer built from the packed packages, on Expo SDK 58 and React Native 0.88. It renders an app using useLocalActions, a Zustand store and useClock under jest-expo, fires onChangeText, onValueChange and onPress, then bundles the app for Android with Metro and Hermes.