Reactjs Redux表单不接受数据
我试图实现redux表单。但由于某些情况,它不会从键盘接收任何输入。有人能调查一下吗 表单组件:Reactjs Redux表单不接受数据,reactjs,redux,Reactjs,Redux,我试图实现redux表单。但由于某些情况,它不会从键盘接收任何输入。有人能调查一下吗 表单组件: import React from 'react'; import {connect} from 'react-redux'; import fetchTasks from '../actions/getTasks'; import InputForm from './inputfrom'; import showResults from './showResult'; class Homepag
import React from 'react';
import {connect} from 'react-redux';
import fetchTasks from '../actions/getTasks';
import InputForm from './inputfrom';
import showResults from './showResult';
class Homepage extends React.Component{
componentDidMount(){
this.props.fetchtsk();
}
render(){
return(
<div>
<h1>Welcome to My Task-Manager Page</h1>
<InputForm onSubmit={showResults} />
<h3>Here are the tasks:</h3>
<h4>Unchecked:</h4>
{this.props.root.map((item,index)=>{
if(item.isChecked===0)
return (<div><span key={index}>{item.data}</span><input type='checkbox' onClick={()=>this.props.changeCheck(item.insertionId)}></input></div>)
return null;
})}
<h4>Checked:</h4>
{this.props.root.map((item,index)=>{
if(item.isChecked===1)
return (<div><span key={index}>{item.data}</span><input type='checkbox' checked="checked" onClick={()=>this.props.changeCheckR(item.insertionId)}></input></div>)
return null;
})}
</div>
)
}
}
const matchStatetoProps = (state) =>{
return {root:state.root};
}
const dispatchStatetoProps = (dispatch) =>{
return{
fetchtsk:()=> dispatch(fetchTasks),
changeCheck: (insertionId)=> dispatch({type:'CHANGECHK',payload:insertionId}),
changeCheckR: (insertionId)=> dispatch({type:'CHANGECHKR',payload:insertionId})
}
}
export default connect(matchStatetoProps,dispatchStatetoProps)(Homepage);
当我按任意键时,相应的值都不会反映出来。它看起来像一个没有响应的文本区域
您在控制台上有任何错误吗?检查showResults功能否,我在控制台中没有任何错误
import React from 'react';
import {connect} from 'react-redux';
import fetchTasks from '../actions/getTasks';
import InputForm from './inputfrom';
import showResults from './showResult';
class Homepage extends React.Component{
componentDidMount(){
this.props.fetchtsk();
}
render(){
return(
<div>
<h1>Welcome to My Task-Manager Page</h1>
<InputForm onSubmit={showResults} />
<h3>Here are the tasks:</h3>
<h4>Unchecked:</h4>
{this.props.root.map((item,index)=>{
if(item.isChecked===0)
return (<div><span key={index}>{item.data}</span><input type='checkbox' onClick={()=>this.props.changeCheck(item.insertionId)}></input></div>)
return null;
})}
<h4>Checked:</h4>
{this.props.root.map((item,index)=>{
if(item.isChecked===1)
return (<div><span key={index}>{item.data}</span><input type='checkbox' checked="checked" onClick={()=>this.props.changeCheckR(item.insertionId)}></input></div>)
return null;
})}
</div>
)
}
}
const matchStatetoProps = (state) =>{
return {root:state.root};
}
const dispatchStatetoProps = (dispatch) =>{
return{
fetchtsk:()=> dispatch(fetchTasks),
changeCheck: (insertionId)=> dispatch({type:'CHANGECHK',payload:insertionId}),
changeCheckR: (insertionId)=> dispatch({type:'CHANGECHKR',payload:insertionId})
}
}
export default connect(matchStatetoProps,dispatchStatetoProps)(Homepage);
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
export default (async function showResults(values) {
await sleep(500); // simulate server latency
window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`);
});