Skip to content

Commit

Permalink
Update awareness example
Browse files Browse the repository at this point in the history
  • Loading branch information
neftaly authored Nov 8, 2023
1 parent effbf69 commit d98f9a9
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions examples/react-use-awareness/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ export function App({ userId }) {

return (
<div>
<input
type="number"
value={newCount ?? count}
placeholder={count}
style={{ color: newCount ? "red" : "black" }}
onChange={(e) =>
updateLocalState((state) => ({
...state,
count: e.target.value,
}))
}
/>
<p>
This is an example of useAwareness, which is used to share ephemeral state that won't be saved to the document.
It's most commonly used for showing which peers are online and their cursor positions, but you can use any serializable data you'd like.
</p>
<hr />
<div>
Ephemeral state:
<input
type="number"
value={newCount ?? count}
placeholder={count}
style={{ color: newCount ? "red" : "black" }}
onChange={(e) =>
updateLocalState((state) => ({
...state,
count: e.target.value,
}))
}
/>
</div>
<div>
Doc state:
<span
Expand Down Expand Up @@ -65,7 +73,7 @@ export function App({ userId }) {
})
}
disabled={newCount === undefined}
children="commit"
children="commit to doc"
/>
<button
onClick={() =>
Expand Down

0 comments on commit d98f9a9

Please sign in to comment.