小编Leo*_*Leo的帖子

TSLint:'NavigationState'类型中不存在属性'params'

我在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)

我假设我应该定义传递道具的类型但是什么是正确的方法?

typescript react-native react-navigation

9
推荐指数
1
解决办法
1510
查看次数

我可以在react-native中使用reactJS库吗?

嗯,这可能是一个愚蠢的问题,但我想澄清原因.React-Native导入nodeJS库,所以我认为也可以使用reactJS库,尽管reactJS包含纯html组件.

可以反应原生识别reactJS组件,包括HTML?

javascript node.js reactjs react-native

7
推荐指数
1
解决办法
2833
查看次数

如何永远运行 React Boilerplate

我将永远在服务器中运行react-boilerplate应用程序。我找到了永远,我不确定如何将参数传递给永远。运行服务器的命令如下:

PORT=80 npm run start:production

似乎forever start PORT=80 npm run start:production对我没有帮助。

javascript deployment node.js forever react-boilerplate

5
推荐指数
1
解决办法
6000
查看次数

功能组件比类组件有更好的性能?

在 react hooks 之前,我们将功能组件称为无状态组件。当时它确实比类组件快,但现在呢?

由于我们有反应钩子,无状态组件不再精确。功能组件是否比运行相同功能的类组件更快?

例如在功能组件中,

  • 我可以state使用useState钩子处理变量。
  • useEffect可以代表componentDidMountcomponentWillReceiveProps或类组件中的其他一些生命周期方法。
  • …………

我们还有很多其他的钩子函数,但是哪些钩子能让我的类组件更快或更轻?

performance reactjs react-native react-hooks

5
推荐指数
1
解决办法
1136
查看次数

当路由改变时react-router-dom刷新组件

我为不同的路线使用了相同的组件。当路由改变时,我希望组件被渲染。

<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不会刷新。

什么是很酷的方法?

javascript reactjs react-router

4
推荐指数
2
解决办法
2万
查看次数

React+Typescript+Webpack项目中Jest配置错误

我遇到了以下问题。仅供参考,我是 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 testing reactjs webpack jestjs

3
推荐指数
1
解决办法
1829
查看次数