Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@little-saga/use-saga
Advanced tools
Run little-saga inside a React component using React hooks.
使用 React hooks 特性 在一个组件的生命周期内运行 little-saga。
该类库提供了一个函数 useSaga
,用于在一个 React 函数组件的生命周期内运行 saga。useSaga
像是 useReducer
的增强版,useSaga
在创建 redux-like 状态容器的同时会启动我们所提供的 saga;当组件卸载时,saga 会自动结束运行。
注意事项:
import useSaga from '@little-saga/use-saga'
function OurReactComponent() {
const [state, dispatch] = useSaga(options)
// ... 其他代码 ...
}
参数 options
是一个对象,具体字段如下:
字段 | 类型 | 默认值 | 含义 |
---|---|---|---|
saga | 生成器函数 | 必须字段 | 所要执行的 saga 函数 |
args | 数组 | [] | 启动 saga 函数时所使用的参数 |
reducer | 函数 | x => x | 指定 state 如何响应 actions |
initialState | 任意值 | undefined | 初始状态 |
initialAction | 任意合法的 action | undefined | 创建状态容器时用于初始化状态的 action 详见 useReducer 文档 |
customEnv | 任意值 | undefined | 指定 运行运行环境对象中的额外字段 详见 runSaga#options.customEnv |
taskContext | 普通对象 | undefined | root task 的初始 context 详见 runSaga#options.taskContext |
useSaga
的返回值与 useReducer
的返回值相同,一般我们可以用数组解构的方式将其赋值给变量 state
与 dispatch
。state
表示当前状态容器的最新状态,dispatch
用于向状态容器 / saga 运行时派发 action。
FAQs
Run little-saga inside a React component using React hooks.
We found that @little-saga/use-saga 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.