我正在使用 Vite 创建一个新的 React + TypeScript 项目。
创建项目后,根文件夹中有两个 TypeScript 配置文件:tsconfig.json和tsconfig.node.json. 以下是每一篇的内容:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}
Run Code Online (Sandbox Code Playgroud)
为什么我们需要两个?
第二个是做什么的?
我可以删除第二个吗?
我有这两个函数,具有重复的异常处理,其唯一目的是显示错误消息:
void func1() noexcept {
try {
do_task();
do_another_task();
} catch (const std::out_of_range& e) {
show_msg("Out of range error", e.what());
} catch (const std::logic_error& e) {
show_msg("Logic error", e.what());
} catch (const std::system_error& e) {
show_msg("System error", e.what());
} catch (const std::runtime_error& e) {
show_msg("Runtime error", e.what());
} catch (const std::exception& e) {
show_msg("Generic error", e.what());
}
}
void func2() noexcept {
try {
do_something();
do_something_else();
do_even_more();
} catch (const std::out_of_range& e) {
show_msg("Out of range error", e.what());
} catch …Run Code Online (Sandbox Code Playgroud) 我正在使用 TypeScript 构建一个 Vue 库。我想导出组件的文档,就像导出普通函数一样。
以前我们会这样做:
<script>
/**
* This is the documentation of my component.
*/
export default {
}
</script>
<template></template>
Run Code Online (Sandbox Code Playgroud)
但现在script setup:
<script setup lang="ts">
</script>
<template></template>
Run Code Online (Sandbox Code Playgroud)
我们如何记录组件?
Vue 有这个nextTick函数,它是一个等待 DOM 刷新的异步函数。当您想要直接对元素执行某些操作(例如使用 滚动 DIV)时,这特别有用scroll()。这避免了将此调用包装到盲注中的需要setTimeout()。
在React中我就求助于setTimeout()过去。是否有相当于nextTick()或有更好的方法来做到这一点?
在React中,对于类,我可以在组件加载时将焦点设置为输入,如下所示:
class Foo extends React.Component {
txt1 = null;
componentDidMount() {
this.txt1.focus();
}
render() {
return (
<input type="text"
ref={e => this.txt1 = e}/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用新的钩子提议重写此组件.
我想我应该使用useEffect而不是componentDidMount,但我怎样才能重写焦点逻辑?
当使用带有自定义反应脚本的create-react-app时,我总是最终安装了React 16(最新)。有没有办法使用旧版本(例如React 15)创建新项目?
我正在使用 Go 1.13.1,截至今天最新。
我正在尝试go get从 GitHub 中完全删除我安装的软件包。本go clean -i <PACKAGE_NAME>似乎没有工作,因为有文件通过传播,至少,这些目录:
~/go/pkg/mod/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/<PACKAGE_NAME>
Run Code Online (Sandbox Code Playgroud)
有没有办法在不手动删除所有内容的情况下清理所有内容?
假设我有以下React组件:
const Compo1 = ({theName}) => {
return (
<Nested foo={() => console.log('Dr. ' + theName)}/>
);
};
const Compo2 = ({theName}) => {
function theFoo() {
console.log('Dr. ' + theName);
}
return (
<Nested foo={theFoo}/>
);
};
Run Code Online (Sandbox Code Playgroud)
和嵌套的组件,包裹在memo:
const Nested = React.memo(({foo}) => {
return (
<Button onClick={foo}>Click me</Button>
);
});
Run Code Online (Sandbox Code Playgroud)
在传递函数foo中总是重建中Compo1还Compo2,是否正确?
如果是这样,既然foo每次都收到一个新功能,是否意味着memo将无用,从而Nested总是被重新渲染?
Cargo 功能允许条件编译,因此最终版本将仅包含可由最终用户过滤的特定功能组。
现在,根据库箱的复杂性,您可能会以形成依赖树的几个功能结束,例如:
[features]
banana = []
avocado = []
pineapple = ["avocado"]
orange = ["pineapple", "banana"]
Run Code Online (Sandbox Code Playgroud)
很自然,除此之外cargo check|test --all-features,我会希望cargo check|test --features banana在每一项单独的功能上运行,以确保它们能够独立运行。目前,我正在使用一个粗略的 shell 脚本来完成此操作,并手动提供这些功能。如果我添加一个新功能但忘记将其添加到脚本中,我就会遇到麻烦。
FEATS=(banana avocado pineapple orange)
for FEAT in "${FEATS[@]}" ; do
echo "$FEAT..."
cargo check --features "$FEAT"
#cargo test --features "$FEAT"
done
Run Code Online (Sandbox Code Playgroud)
那么,是否有任何自动化方法可以cargo check|test --features banana逐一运行每个功能,然后报告已发现的警告/错误?
javascript ×5
reactjs ×4
go ×2
typescript ×2
vue.js ×2
c++ ×1
c++11 ×1
debugging ×1
delve ×1
dom ×1
go-modules ×1
jsdoc ×1
memo ×1
package ×1
rust ×1
rust-cargo ×1
tsconfig ×1
vite ×1