deno.land / x / solid_signals@solid-signals@1.3.7 / src / signals / composable / createObject
Extends signal setter with update
method. See Reference for more details.
import { createObject } from "solid-signals";
function ExampleComponent {
const [object, setObject] = createObject({ prop1: "value1", prop2: "value2" });
return (
<div>
<button onClick={() => {
setObject.update({ prop1: "updated" });
}}>
Update prop1
</button>
<button onClick={() => {
setObject.update({ prop2: "updated" });
}}>
Update prop2
</button>
object: {JSON.stringify(object())}
</div>
);
}
object: { "prop1": "value1", "prop2": "value2" }
[Click: Update prop1]
object: { "prop1": "updated", "prop2": "value2" }
[Click: Update prop2]
object: { "prop1": "updated", "prop2": "updated" }
import { createHistory, createObject } from "solid-signals";
function ExampleComponent {
const [object, setObject] = createObject.wrap(createHistory({ prop1: "value1", prop2: "value2" }));
return (
<div>
<button onClick={() => {
setObject.update({ prop1: "updated" });
}}>
Update prop1
</button>
<button onClick={() => {
setObject.update({ prop2: "updated" });
}}>
Update prop2
</button>
<button onClick={() => {
setObject.history.back();
}}>
Back
</button>
object: {JSON.stringify(object())}
</div>
);
}
object: { "prop1": "value1", "prop2": "value2" }
[Click: Update prop1]
object: { "prop1": "updated", "prop2": "value2" }
[Click: Update prop2]
object: { "prop1": "updated", "prop2": "updated" }
[Click: Back]
object: { "prop1": "updated", "prop2": "value2" }
[Click: Back]
object: { "prop1": "value1", "prop2": "value2" }
setState.update(updates: Partial<T>): void
Merges given object with current state. Allows for specific property updates without affecting other properties
Version Info