Reputation: 95
thats my submitTask.tsx which is a separate file
import React from "react";
import { SubmissionError } from "redux-form";
import { Redirect } from "react-router-dom";
import { Dispatch } from "redux";
import { addNewTask } from "../actions/Task";
const submitTask = (values: any, dispatch: Dispatch) => {
if (!values.category || !values.description) {
throw new SubmissionError({
_error: "All fields are required!"
});
} else {
const taskValue = {
id: values.id,
category: values.category,
description: values.description,
createdAt: values.createdAt
};
dispatch(addNewTask(taskValue));
return <Redirect to="/tasks" />; //this line causing problem when i add it
}
};
export default submitTask;
here is an error message from TaskForm.tsx, did any one have any idea whats wrong here?
Upvotes: 0
Views: 74
Reputation:
Because functions return some value or data, not JSX.
To redirect you should try something like that:
myForm = () => {
if(condition from redux store or local state){
return <Redirect to={"/tasks"}/>
}
return (
<ReduxForm onSubmit = {some function}/>
);
}
Upvotes: 1