我如何从URL获取类道具并将其存储在react-redux中

时间:2020-05-30 14:33:18

标签: reactjs react-redux

所以我试图使用路由将参数传递给react组件,同时也使用Component类的props。这是在做什么

if(fromAccount.getCurrentBalance().compareTo(BigDecimal.ONE) == 1
        && fromAccount.getCurrentBalance().compareTo(amount) == 1
){
    fromAccount.setCurrentBalance(fromAccount.getCurrentBalance().subtract(amount));
    accountRepository.save(fromAccount);
    toAccount.setCurrentBalance(toAccount.getCurrentBalance().add(amount));
    accountRepository.save(toAccount);
    Transaction transaction = transactionRepository.save(new Transaction(0L,fromAccountNumber,amount,new Timestamp(System.currentTimeMillis())));
    return transaction;
}
return null;

我对此组件的网址为

import { loadSchemes, } from '../../actions/schemes;

export class Schemes extends Component {
constructor(props) {
    super(props);
    const { match: { params } } = this.props;
    this.state = {
      client_id: params.pk,
    }
  }
componentDidMount() {
    this.props.loadSchemes();
  }
render(){
 return(
   <div>
    {this.props.schemes_list.map((scheme,index)=><p key={index}>{scheme}</p>)}
   </div>
  )
 }
}
const mapStateToProps = (state) => ({
  schemes_list: state.schemes,
});
export default connect(mapStateToProps,{ loadSchemes,})(Schemes);

问题是我收到错误 this.props.schemes_list未定义 this.props.loadSchemes未定义

请帮助我使用react-redux

1 个答案:

答案 0 :(得分:0)

很明显,在您从中调用Scheme的组件中,导入{Schemes}(未连接的组件),而不是Schemes-默认的已连接组件。请检查一下。