我创建了一个应用程序,在其中我添加了课程,我创建了动作和减速器,但无法找出我在哪里做了错误的
Action courses.js代码
import {coursesRef} from '../services/fire';
const FETCH_COURSES = 'FETCH_COURSES';
export const addCourse = newCourse => async dispatch => {
coursesRef.push().set(newCourse);
};
Reducer courses.js代码
const iState = {}
const courses = (state = iState, action) => {
switch (action.type) {
case 'ADD_COURSES':
return { ...state, [action.payload.user]: action.payload }
default:
return state
}
};
export default course
Addcourse.js代码
以下是Addcorse.js代码
const AddCourse=()=>{
const [course, setCourse] = useState('');
const dispatch = useDispatch();
const user = useSelector(state => state.auth.user);
useEffect(()=>{
document.title= "Add Courses"
},[])
const addCourse = () => {
const payload = { user:user, text: course}
>我认为问题出在孩子身上("课程"(,但不知道是仪式
const dbcoursesWrapper = database.ref().child(user).child('courses');
return dbcoursesWrapper.child(payload.user).update(payload).then(() => {
setCourse('');
dispatch({ type: "ADD_COURSES", payload })
})
}
return(
<div>
<h1 className="text-center my-3">Fill Course Detail</h1>
<Form onSubmit={e => {
e.preventDefault(e.target.value);
addCourse();
} }>
<FormGroup>
<label for="UserId">Course Id</label>
<Input
type="text"
onChange={e => setCourse(e.target.value)}
placeholder="Enter your Id"
name="userId"
id="UserId"
/>
</FormGroup>
<FormGroup>
<label for="title">Course Title</label>
<Input
type="text"
placeholder="Enter Course Title"
name="title"
id="title"
/>
</FormGroup>
<label for="description">Course Description</label>
<Input
type="textarea"
placeholder="Enter Course Description"
name="description"
id="description"
style={{ height: 150}}
/>
<Container className="text-center">
<Button color="success">Add Course</Button>
<Button color="warning ml-3">clear</Button>
</Container>
</Form>
</div>
);
};
export default AddCourse;
我认为问题不在您在这里发布的任何代码中,错误是说它试图对名为pathString
的变量执行.replace()
,但失败了。
它很可能会失败,因为pathString
实际上不是一个字符串。你能提供一个进一步的堆栈跟踪吗,因为如果没有它,就很难诊断出哪里有错误。