使用const [open, setOpen] = useState(false)我可以创建一个变量open,该变量通过功能组件的调用而持久化。
但是如果我在设置变量时不想重新渲染,我可以使用哪个钩子?
我有一个自定义钩子草稿:
const useVariable = (initialValue) => {
const ref = useRef();
return useMemo(() => {
ref.current = [initialValue, (newValue) => { ref.current[0] = newValue }]
}, [])
}
Run Code Online (Sandbox Code Playgroud)
但是根据https://reactjs.org/docs/hooks-reference.html#usememo我不能相信 useMemo 不会再次被调用。
我做了以下事情:
npm install TuningGuide/react-sortable-hoc --save
npm info it worked if it ends with ok
npm info using npm@3.10.5
npm info using node@v6.2.2
npm info git [ 'clone',
npm info git '--template=/Users/velten/.npm/_git-remotes/_templates',
npm info git '--mirror',
npm info git 'git://github.com/tuningguide/react-sortable-hoc.git',
npm info git '/Users/velten/.npm/_git-remotes/git-github-com-tuningguide-react-sortable-hoc-git-78a804e9' ]
npm info git [ 'rev-list', '-n1', 'master' ]
npm info git [ 'clone',
npm info git '/Users/velten/.npm/_git-remotes/git-github-com-tuningguide-react-sortable-hoc-git-78a804e9',
npm info git '/var/folders/95/ylk5ht9s24n6xk4rcr6sch4r0000gn/T/npm-22395-24e6f9cc/git-cache-220f34bb/09fb1e0c7d657657b9aa091c018b45aee0ed0662' ]
npm info git [ 'checkout', '09fb1e0c7d657657b9aa091c018b45aee0ed0662' ]
npm info git [ 'submodule', '-q', 'update', …Run Code Online (Sandbox Code Playgroud) 我创建了一个类,可以使用它获取正则表达式对象中组的所有开始和结束位置(https://github.com/valorize/MultiRegExp2)。我想用这个新的“类”包装初始正则表达式并添加一个新方法execForAllGroups。我怎样才能做到这一点/覆盖旧的正则表达式但仍然使用它的所有功能,如搜索、测试等?
我有:
function MultiRegExp2(baseRegExp) {
let filled = fillGroups(baseRegExp);
this.regexp = filled.regexp;
this.groupIndexMapper = filled.groupIndexMapper;
this.previousGroupsForGroup = filled.previousGroupsForGroup;
}
MultiRegExp2.prototype = new RegExp();
MultiRegExp2.prototype.execForAllGroups = function(string) {
let matches = RegExp.prototype.exec.call(this.regexp, string);
...
Run Code Online (Sandbox Code Playgroud)
编辑:感谢 TJ Crowder,我调整了 ES6 类语法并扩展了 RegExp:
class MultiRegExp extends RegExp {
yourNiftyMethod() {
console.log("This is your nifty method");
}
}
But
let rex = new MultiRegExp(); // rex.constructor.name is RegExp not MultiRegExp
rex.yourNiftyMethod(); // returns: rex.yourNiftyMethod is not a function
Run Code Online (Sandbox Code Playgroud)
当我从 String …
当我使用自己选择的键时,我知道第一个字符是在“_”之前还是之后(小写键、整数键或另一方面大写键),但是当我使用自动生成的键时,我不知道。
那么我怎样才能排除以“_design”开头的所有内容呢?
db.allDocs({include_docs: true, startkey: ???});
Run Code Online (Sandbox Code Playgroud) couchdb ×1
github ×1
javascript ×1
node.js ×1
npm ×1
oop ×1
pouchdb ×1
react-hooks ×1
reactjs ×1