我在react-native开发中使用typescript.我通过params来筛选navigate功能.
this.props.navigation.navigate("NextScreen", { title: "title" })
Run Code Online (Sandbox Code Playgroud)
在NextScreen我访问params通过this.props.navigation.state.params.title但我得到tslint错误params.
TS2339:Property 'params' does not exist on type 'NavigationState'.
Run Code Online (Sandbox Code Playgroud)
这是一些代码.
import { NavigationInjectedProps } from "react-navigation";
interface OwnProps {
}
interface OwnState {
}
type Props = NavigationInjectedProps & OwnProps;
class NextScreen extends React.Component<Props, OwnState> {
...
public render() {
// tslint error occurs in this line.
const { title } = this.props.navigation.state.params;
...
}
}
Run Code Online (Sandbox Code Playgroud)
我假设我应该定义传递道具的类型但是什么是正确的方法?
嗯,这可能是一个愚蠢的问题,但我想澄清原因.React-Native导入nodeJS库,所以我认为也可以使用reactJS库,尽管reactJS包含纯html组件.
可以反应原生识别reactJS组件,包括HTML?
我将永远在服务器中运行react-boilerplate应用程序。我找到了永远,我不确定如何将参数传递给永远。运行服务器的命令如下:
PORT=80 npm run start:production
似乎forever start PORT=80 npm run start:production对我没有帮助。
在 react hooks 之前,我们将功能组件称为无状态组件。当时它确实比类组件快,但现在呢?
由于我们有反应钩子,无状态组件不再精确。功能组件是否比运行相同功能的类组件更快?
例如在功能组件中,
state使用useState钩子处理变量。useEffect可以代表componentDidMount,componentWillReceiveProps或类组件中的其他一些生命周期方法。我们还有很多其他的钩子函数,但是哪些钩子能让我的类组件更快或更轻?
我为不同的路线使用了相同的组件。当路由改变时,我希望组件被渲染。
<Switch>
<Route exact path="/" component={HomePage} />
<Route path="/hotels" component={HotelsPage} />
<Route path="/apartments" component={HotelsPage} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
当我将路由路径从 更改/hotels为 时/apartments,组件HotelsPage不会刷新。
什么是很酷的方法?
我遇到了以下问题。仅供参考,我是 Jest 的初学者,所以请让我知道配置 Jest 时出了什么问题。
webpack.config.js
...
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.scss'],
alias: {
'webextension-polyfill-ts': path.resolve(
path.join(__dirname, 'node_modules', 'webextension-polyfill-ts')
),
reducers: path.resolve(__dirname, 'source/redux'),
routers: path.resolve(__dirname, 'source/routers'),
source: path.resolve(__dirname, 'source'),
...
},
},
...
Run Code Online (Sandbox Code Playgroud)
这是 Jest 配置package.json
"jest": {
...
"moduleNameMapper": {
"^reducers": "<rootDir>/source/redux/$1",
"^routers": "<rootDir>/source/routers/$1",
"^source": "<rootDir>/source/$1",
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
但我在运行测试文件时遇到以下错误。
Configuration error:
Could not locate module source-map-support mapped as:
/Volumes/WORK/Development/project/source/$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^source/": "/Volumes/WORK/Development/project/source/$1"
},
"resolver": …Run Code Online (Sandbox Code Playgroud) javascript ×4
reactjs ×4
react-native ×3
node.js ×2
deployment ×1
forever ×1
jestjs ×1
performance ×1
react-hooks ×1
react-router ×1
testing ×1
typescript ×1
webpack ×1