
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@cohook/solid-js
Advanced tools
Solid-js lightweight, progressive data caching and cross-component communication
@cohook/solid-js
Solid JS 轻量级、渐进式数据缓存和跨组件通信方案
yarn add @cohook/solid-js
npm i @cohook/solid-js
import createContainer from "@cohook/solid-js"
const container = createContainer(0)
const inc = () => container.commit((draft) => void (draft.current += 1)
const dec = () => container.commit((draft) => void (draft.current -= 1)
function Counter() {
const countAccessor = counterContainer.useMapDataToAccessor()
return (
<div>
count:{countAccessor()}
<button onClick={() => inc()}>+</button>
<button onClick={() => dec()}>-</button>
</div>
)
}
createContainer(initialData)
createContainer作为容器工厂函数,接收初始数据initialData
,返回一个容器对象container
。
container
container.useMapDataToAccessor()
用于将数据状态化,被状态化后的数据会自动跟踪变化并更新。
container.commit(updater)
commit 接受一个函数updater(和SolidJS的produce的参数基本保持一致)作为参数,,用来创建修改数据的Action,可灵活组合容器对象提供的方法来组装Action。
const dec = () => container.commit((draft) => void (draft.current -= 1)
createContainerWithPlugins(initialData, pluginsOption)
createContainer作为容器工厂函数,接收初始数据initialData
和插件配置pluginsOption 👉
,返回一个带有插件的容器对象containerWithPlugins
。
containerWithPlugins
containerWithPlugins.getData()
用于获取当前的容器数据,就像是一个内置的action,可在任何地方使用。
containerWithPlugins.useMapDataToAccessor()
用于将数据状态化,被状态化后的数据会自动跟踪变化并更新。
containerWithPlugins.commit(updater)
commit 接受一个函数updater(和SolidJS的produce的参数基本保持一致)作为参数,,用来创建修改数据的Action,可灵活组合容器对象提供的方法来组装Action。
const dec = () => {
const count = containerWithPlugins.getData()
if(count < 0) return
containerWithPlugins.commit((draft) => void (draft.current -= 1)
}
FAQs
Solid-js lightweight, progressive data caching and cross-component communication
We found that @cohook/solid-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.