examples/react/README.md
This is an example of a basic ElectricSQL app using React. The Electric-specific code is in ./src/Example.tsx.
This example is part of the ElectricSQL monorepo and is designed to be built and run as part of the pnpm workspace defined in ../../pnpm-workspace.yaml.
Navigate to the root directory of the monorepo, e.g.:
cd ../../
Install and build all of the workspace packages and examples:
pnpm install
pnpm run -r build
Navigate back to this directory:
cd examples/react
Start the example backend services using Docker Compose:
pnpm backend:up
Note that this always stops and deletes the volumes mounted by any other example backend containers that are running or have been run before. This ensures that the example always starts with a clean database and clean disk.
Now start the dev server:
pnpm dev
You should see three items listed in the page. These are created when first running the ./db/migrations.
Now let's connect to Postgres, e.g.: using psql:
psql "postgresql://postgres:password@localhost:54321/electric"
Insert new data and watch it sync into the page in real time:
insert into items (id) values (gen_random_uuid());
When you're done, stop the backend services using:
pnpm backend:down