mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
docs: simplify examples
This commit is contained in:
parent
0f2f2d642c
commit
682b3dfcff
1 changed files with 12 additions and 6 deletions
18
README.md
18
README.md
|
|
@ -801,13 +801,15 @@ Check out this simple [example project →](https://github.com/littensy/charm-ex
|
||||||
### React Counter
|
### React Counter
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local counterStore = require("./stores/counterStore")
|
local getCounter, setCounter = signal(0)
|
||||||
|
|
||||||
local function Counter()
|
local function Counter()
|
||||||
local count = useSignalState(counterStore.getCounter)
|
local count = useSignalState(getCounter)
|
||||||
|
|
||||||
return React.createElement("TextButton", {
|
return React.createElement("TextButton", {
|
||||||
[React.Event.Activated] = counterStore.incrementCounter,
|
[React.Event.Activated] = function()
|
||||||
|
setCounter(count + 1)
|
||||||
|
end,
|
||||||
Text = `Count: {count}`,
|
Text = `Count: {count}`,
|
||||||
Size = UDim2.fromOffset(100, 50),
|
Size = UDim2.fromOffset(100, 50),
|
||||||
})
|
})
|
||||||
|
|
@ -817,13 +819,17 @@ end
|
||||||
### Vide Counter
|
### Vide Counter
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local counterStore = require("./stores/counterStore")
|
local getCounter, setCounter = signal(0)
|
||||||
|
|
||||||
local function Counter()
|
local function Counter()
|
||||||
local count = useSignalState(counterStore.getCounter)
|
local count = useSignalState(getCounter)
|
||||||
|
|
||||||
return create "TextButton" {
|
return create "TextButton" {
|
||||||
Activated = counterStore.incrementCounter,
|
Activated = function()
|
||||||
|
setCounter(function(count)
|
||||||
|
return count + 1
|
||||||
|
end)
|
||||||
|
end,
|
||||||
Text = function()
|
Text = function()
|
||||||
return `Count: {count()}`
|
return `Count: {count()}`
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue