小编moo*_*oon的帖子

mapStateToProps不更新

我刚开始玩react/redux.我只想输入一些文本并点击提交,然后将其传递给另一个显示输入内容的组件.

我知道我可以从A点到B点获取数据,因为如果我使用store.subscribe而不是我可以访问状态并且它总是准确的.我试图使用mapStateToProps,但我没有运气.

我没有使用mapDispatchToProps所以这可能是一个问题?我似乎无法找到一个很好的简单例子.mapStateToProps似乎也只在我刷新页面时运行(使用webpack-dev-server),因为它只在页面加载时记录一次,而不再记录.

_______________ Input.js _________________

import React from 'react';
import store from '../redux/store';
import { connect } from 'react-redux';
import { addSearchParam } from '../redux/actions';

export default class Input extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      player: ''
    };

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {
    this.setState({
      player: event.target.value
    });
  }

  handleSubmit(event) {
    event.preventDefault();
    store.dispatch(addSearchParam(this.state.player))
  }

  render() {
    return ( <form onSubmit = {this.handleSubmit} >
      <label>
          <input type="text" value={this.state.player} 
          onChange={this.handleChange}/> 
      </label> 
      <input type="submit" value="Submit" /> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-redux

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

如何在 TypeScript 中转换或更改泛型类型?

function cast<R, T>(v: T): R {
  return v as R;
         ~~~~~~
         // Error
}
Run Code Online (Sandbox Code Playgroud)

所以我想做的是将类型v从 T 更改为 R。但是,我看到以下错误。

Conversion of type 'T' to type 'R' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  'T' is assignable to the constraint of type 'R', but 'R' could be instantiated with a different subtype of constraint '{}'.
Run Code Online (Sandbox Code Playgroud)

并且使用InstanceType<typeof R>也给了我一个错误。有人知道如何做到这一点吗?

typescript

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

为什么在 array.map() 中多次生成 React-Tooltip?

最近我开始使用 ReactJS,我是一个超级初学者。这可能是一个非常简单的问题,但我不知道如何解决这个错误。

我在 this.state 中有 3 个图像,并使用 .map() 将它们展开到屏幕上。还有我从https://www.npmjs.com/package/react-tooltip下载的 ReactTooltip

但是有一些我无法修复的错误,它甚至没有显示在控制台屏幕上。问题是每当您将鼠标放在图像上时,就会多次生成 ReactTooltip。任何人都可以帮我解决这个问题吗?

这是我的代码和示例演示。
演示:http : //tooltip-test-moonformeli.c9users.io/
代码:在此处输入图片说明

感谢您的时间!

javascript tooltip reactjs

0
推荐指数
1
解决办法
2603
查看次数

标签 统计

javascript ×2

reactjs ×2

react-redux ×1

tooltip ×1

typescript ×1