我有一些有效的代码。它立即将用户从/test页面重新路由到FinishedPaying页面。是这样的:
class Test extends Component {
renderRedirect = () => {
return <Redirect to="/FinishedPaying" />;
};
componentDidMount() {
this.renderRedirect();
}
...
Run Code Online (Sandbox Code Playgroud)
以下代码用于发送Paypal交易,然后将用户路由到/FinishedPaying页面。所有其他逻辑都按预期工作:
export default class Pay extends React.Component {
state = {
userInput: ""
};
renderRedirect = () => {
return (
<Redirect
to="/FinishedPaying"
userInput={this.state.userInput}
/>
);
};
componentDidMount() {
this.setState({ userInput: this.props.userInput });
this.renderRedirect();
}
render() {
const onSuccess = payment => {
axios
.post(
"http://amazonaws.com:3000/ethhash",
{
userInput: this.props.userInput,
}
) …Run Code Online (Sandbox Code Playgroud) 我有一个需要放入状态的文件对象。我尝试这样做的原因是它被提供作为重新渲染 DOM 的可能解决方案,以便清除 FileReader() 中的值。这是当前线程源自的链接
我将在此处放置一个精简的 React 组件,以便您可以看到发生了什么。
import React, { Component } from "react";
class SearchPage extends Component {
constructor(props) {
super(props);
this.state = {
files: []
};
}
onChange(e) {
let files = e.target.files;
this.setState({ files: files[0] });
console.log(files[0]);
console.log(this.state.files)
}
render() {
return (
<div onSubmit={this.onFormSubmit}>
<input type="file" name="file" onChange={e => this.onChange(e)} />
</div>
);
}
}
export default SearchPage;
Run Code Online (Sandbox Code Playgroud)
console.log(files[0]} 给出了这样的东西:
File(1) {name: "1.txt", lastModified: 1549429792266, lastModifiedDate: Tue Feb 05 2019 22:09:52 GMT-0700 (Mountain …Run Code Online (Sandbox Code Playgroud)