Installation
To get started with Valtio, you can install it using your favorite package manager.
npm
npm install valtio
yarn
yarn add valtio
pnpm
pnpm add valtio
Peer Dependencies
If you are using Valtio with React, you need to have react
installed in your project. Valtio supports React 18 and newer.
From package.json
:
"peerDependencies": {
"@types/react": ">=18.0.0",
"react": ">=18.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"react": {
"optional": true
}
}
This indicates that react
is an optional peer dependency, as Valtio's core can be used in a vanilla JavaScript environment without React. However, for using hooks like useSnapshot
, react
is required.