是否有任何库可以帮助模糊生产的反应构建?
就像是:
const MyComp = () = > {
const {propa, propb} = useMyfunc()
return(...)
}
Run Code Online (Sandbox Code Playgroud)
到
const xyz = () = > {
const {yxz, zyx} = zzz()
return(...)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 getState() 检索状态的一部分以从事件处理程序中的状态中过滤一些值(在调度操作并使用新状态切片更新存储之前)但是更改 getState 的结果似乎改变了实际店铺。
考虑以下:
const filterInPlace = (array, predicate) => {
let end = 0;
for (let i = 0; i < array.length; i++) {
const obj = array[i]
if (predicate(obj)) {
array[end++] = obj
}
}
array.length = end
}
//some event handler
...
const forDeletion = new Set([...ids])
let currentState = getState().home.lists
filterInPlace(currentState, obj => !forDeletion.has(obj.rowid))
dispatch(handleSelectLists(ids)) //Leads to an action and reducer
Run Code Online (Sandbox Code Playgroud)
getState() 会改变存储吗?
在生产中使用 Google 的分析跟踪 ID 是否安全?我假设这不是秘密,我可以做类似的事情:
const location = useLocation();
useEffect(() => {
ReactGA.initialize("UA-MY-GA-ID"); // Analytics tracking ID
ReactGA.ga('send', 'pageview', location.pathname);
}, [location]);
Run Code Online (Sandbox Code Playgroud) 我正在尝试从函数返回结果并提取它的返回值。我正在使用i32and a&str并且在语句中收到不匹配类型错误match(不能在匹配中使用两种不同的类型)。我该如何解决?
fn use_result(par: i32)-> Result<i32, &'static str> {
if par == 0 {
Err("some error")
} else {
println!("par is 1");
Ok(par)
}
}
fn main() {
// Result
let res = match use_result(1) {
Ok(v) => v,
Err(e) => e,
};
}
//Do something with res: v or res: e
Run Code Online (Sandbox Code Playgroud)
}
reactjs ×3
javascript ×1
react-redux ×1
redux ×1
redux-thunk ×1
rust ×1
security ×1
webpack ×1