# React & Preact

Use [`@nanostores/react`](https://github.com/nanostores/react) or [`@nanostores/preact`](https://github.com/nanostores/preact) package and `useStore()` hook to get store’s value and re-render component on store’s changes.

```tsx
import { useStore } from '@nanostores/react' // or '@nanostores/preact'

import { $profile } from '../stores/profile.js'

export const Header = ({ postId }) => {
  const profile = useStore($profile)
  return <header>Hi, {profile.name}</header>
}
```

In React `useLoadingStore()` suspends the component while the store is loading. It supports both loading formats: the state machine of [`@nanostores/async`](https://github.com/nanostores/async) and the `isLoading` key of [Logux Client](https://github.com/logux/client) and [`@nanostores/sql`](https://github.com/nanostores/sql).

stores/user.ts

```ts
import { computedAsync } from '@nanostores/async'
import { atom } from 'nanostores'

export const $userId = atom('user-1')

export const $user = computedAsync($userId, userId => {
  return fetch(`/api/users/${userId}`).then(response => response.json())
})
```

***

*Imported from the [Nano Stores README](https://github.com/nanostores/nanostores/blob/1.5.5/README.md#react--preact) for version 1.5.5. Improve this page there.*
