问题描述
zutand doc 提到如果选择器不依赖于范围,您可以使用选择器并提供下面的示例
我不明白 cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib})
部分。有人可以提供一些示例,说明何时状态取决于范围,因此不应使用选择器?
谢谢!
解决方法
这意味着选择器是一个仅使用 state
对象的函数,因此没有外部依赖项。
有人可以提供一些示例,说明状态何时取决于 范围以便不应使用选择器?
作用域不会影响何时何地可以使用选择器函数,而是可以在何处声明它。除了 state
之外,没有依赖项的选择器函数可以在使用它们的任何组件的外部声明。
您可以编写一个选择器函数,该函数还引用组件中定义的值,因此该值将是外部依赖项。
const MyComponent = () => {
const value = ......;
const selector = state = {
// use enclosed value to compute returned value from state
... do something with value
};
const valueFromState = useStore(selector);
...