How do I manage this form in redux? - reactjs

I'm building an online store and I'm creating a form where the user will select an option and the option's price will be added to the total price
class SingleProduct extends Component {
constructor(props) {
super(props);
this.state = {};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
event.preventDefault();
var products = this.props.products.products;
var ID = this.props.router.location.pathname.slice(9, 100)
var productArray = this.props.products.products.data.filter(function(product) {
return product.id === ID;
})
var product = productArray[0];
var addToCart = (id, options) => {
this.props.dispatch((dispatch) => {
if(this.props.value == 'select'){
this.props.product.options = 0;
}
else if(this.state.value == 'no-edge'){
this.props.product.options = 0;
}
else if(this.state.value == '2inchHemOnly'){
this.props.product.options = 20;
}
else if(this.state.value == '2inchHG'){
this.props.product.options = 25;
}
else if(this.state.value == 'HandG'){
this.props.product.options = 30;
}
else if(this.state.value == 'rope-rail'){
this.props.product.options = 35;
}
else if(this.state.value == 'pole-pocket'){
this.props.product.options = 40;
}
var values = this.props.product.values;
var options = this.props.product.options;
api.AddCart(id, this.props.product.quantity)
.then((options) => {
console.log(options)
dispatch({type: "Update_Options", payload: options})
})
.then((values) => {
console.log(values)
dispatch({type: "Update_Value", payload: values})
})
.then((cart) => {
console.log(cart)
dispatch({type: "Cart_Updated", gotNew: false})
})
.then(() => {
dispatch({type: "Fetch_Cart_Start", gotNew: false})
api.GetCartItems()
.then((cart, options, values) => {
dispatch({type: "Fetch_Cart_End", payload: cart, gotNew: true})
dispatch({type: "Update_Options", payload: options})
dispatch({type: "Update_Value", payload: values})
})
})
.then(() => {
console.error(options)
})
.catch((e) => {
console.log(e)
})
})
}
addToCart(product.id);
}
return (
<main role="main" id="container" className="main-container push">
<section className="product">
<div className="content">
<div className="product-listing">
<div className="product-description">
<p className="price"><span className="hide-content">Unit price </span>{'$' + product.meta.display_price.with_tax.amount/100 + this.props.product.options}</p>
<form className="product" onSubmit={this.handleSubmit.bind(this)}>
<label>SELECT EDGING OPTION</label>
<select name="edging" value={this.state.value} onChange={this.handleChange}>
<option value="select">-- Please select --</option>
<option value="no-edge">No Edge</option>
<option value="2inchHemOnly">2” Hem Only</option>
<option value="2inchHG">2” Hem and Grommets 24” On Center</option>
<option value="HandG">Hem and Grommets 12” on Center</option>
</select>
<div className="quantity-input" style={style}>
<p className="hide-content">Product quantity.</p>
<button type="submit" className="submit">Add to cart</button>
</form>
</div>
</div>
</section>
<MailingList />
</main>
)
}
}
export default connect(mapStateToProps)(SingleProduct);
And here is my reducer:
const initialState = {
quantity: 1,
options: 0,
values: [
{ value: '-- Please select --' },
{ value: 'No Edge' },
{ value: '2” Hem Only' },
{ value: 'No Edge' },
{ value: '2” Hem and Grommets 24” On Center' },
{ value: 'Hem and Grommets 12” on Center' }
]
}
const ProductReducer = (state=initialState, action) => {
switch (action.type) {
case "Update_Quantity": {
return {...state, quantity: action.payload};
}
case "Update_Options": {
return {...state,
options: action.payload};
}
case "Update_Value": {
return {...state,
value: action.payload};
}
default: {
return {...state};
}
}
};
export default ProductReducer;
When I add to the cart my 'value' is undefined. And on refresh, 'options' goes back to 0. My quantity stays in the state though. I just don't know why this is happening.

The react docs state: Whether you declare a component as a function or a class, it must never modify its own props.
Therefore, you might want to make a copy of the props into a variable and then modify the copy. One way to do this might be to place this line:
let propsCopy = { ...this.props }
above the line var addToCart = (id, options) => {
and then use propsCopy in place of props in the subsequent lines.

Related

Iam making a Todo using (useReducer and useContext) but the update functionality is not working please check this out

This is my App.jsx , where iam displaying all the todos, after clicking edit the input gets the value of selected todo and while changing the value and clicking on update it does nothing.
export default function App() {
const { dispatch, state } = useContext(todoContext);
const [todo, setTodo] = useState("");
const [isEditing, setIsEditing] = useState(false);
const [selectedTodo, setSelectedTodo] = useState("");
const handleSubmit = (e) => {
const id = uuidv4();
e.preventDefault();
if (!isEditing) {
dispatch({
type: "ADD_TODO",
payload: { id: id, text: todo },
});
setTodo("");
} else {
dispatch({
type: "UPDATE_TODO",
payload: selectedTodo,
});
setIsEditing(false);
setTodo("");
}
};
const handleEdit = (val) => {
setIsEditing(true);
const item = state.todos.find((todo) => todo.id === val.id);
setTodo(item.text);
setSelectedTodo(item);
};
return (
<div className="App">
<br />
<h1>Hello World This is Todo App</h1>
<br />
<form onSubmit={handleSubmit}>
<input
value={todo}
onChange={(e) => setTodo(e.target.value)}
type="text"
placeholder="Enter a todo"
/>
<button>{isEditing ? "Update" : "Submit"}</button>
</form>
{state.todos.map((item) => (
<div key={item.id} className="todoitem">
<p
onClick={() => dispatch({ type: "TOGGLE_TODO", payload: item.id })}
style={{
cursor: "pointer",
textDecoration: item.completed ? "line-through" : "",
}}
>
{item.text}
</p>
<span
onClick={() => dispatch({ type: "REMOVE_TODO", payload: item.id })}
>
×
</span>
<button onClick={() => handleEdit(item)}>Edit</button>
</div>
))}
</div>
);
}
This is my reducers (todoReducer.jsx) , where the upadte functionality doesnot work when i click edit to change the value and click update it does nothing
export const INITIAL_STATE = {
todos: [],
updated: [],
};
export const reducer = (state, action) => {
switch (action.type) {
case "ADD_TODO":
return {
...state,
todos: [...state.todos, action.payload],
};
case "REMOVE_TODO": {
return {
...state,
todos: state.todos.filter((item) => item.id !== action.payload),
};
}
case "TOGGLE_TODO":
return {
...state,
todos: state.todos.map((todo) =>
todo.id === action.payload
? { ...todo, completed: !todo.completed }
: todo
),
};
case "UPDATE_TODO":
return {
...state,
todos: state.todos.map((todo) => {
if (todo.id === action.payload.id) {
return action.payload;
}
return todo;
}),
};
default:
return state;
}
};
you need to update text with latest text
selectedTodo has old data
todo have new text
in your handleSubmit please update below code
dispatch({
type: "UPDATE_TODO",
payload: { ...selectedTodo, text: todo },
});

Is there a way to handle state in a form that is dynamically built based off of parameters sent from the back end

I have a page in react 18 talking to a server which is passing information about how to build specific elements in a dynamic form. I am trying to figure out how to manage state in a case where there are multiple selects/multiselects in the page. Using one hook will not work separately for each dropdown field.
Code is updated with the latest updates. Only having issues with setting default values at this point. Hooks will not initially set values when given.
import { Calendar } from 'primereact/calendar';
import { Dropdown } from 'primereact/dropdown';
import { InputSwitch } from 'primereact/inputswitch';
import { InputText } from 'primereact/inputtext';
import { MultiSelect } from 'primereact/multiselect';
import React, { useEffect, useState, VFC } from 'react';
import { useLocation } from 'react-router-dom';
import { useEffectOnce } from 'usehooks-ts';
import { useAppDispatch, useAppSelector } from 'redux/store';
import Form from '../components/ReportViewForm/Form';
import { getReportParamsAsync, selectReportParams } from '../redux/slice';
export const ReportView: VFC = () => {
const location = useLocation();
const locState = location.state as any;
const dispatch = useAppDispatch();
const reportParams = useAppSelector(selectReportParams);
const fields: JSX.Element[] = [];
const depList: any[] = [];
//const defaultValList: any[] = [];
//dynamically setting state on all dropdown and multiselect fields
const handleDdlVal = (name: string, value: string) => {
depList.forEach((dep) => {
if (name === dep.dependencies[0]) {
dispatch(getReportParamsAsync(currentMenuItem + name + value));
}
});
setState((prev: any) => {
return { ...prev, [name]: value };
});
};
//dynamically setting state on all calendar fields
const handleCalVal = (name: string, value: Date) => {
setState((prev: any) => {
return { ...prev, [name]: value };
});
};
//dynamically setting state on all boolean fields
const handleBoolVal = (name: string, value: boolean) => {
setState((prev: any) => {
return { ...prev, [name]: value };
});
};
/* function getInitVals(values: any) {
const defaultList: any[] = [];
values.forEach((param: any) => {
defaultList.push({ name: param.name, value: param.defaultValues[0] });
});
} */
const [state, setState] = useState<any>({});
const [currentMenuItem, setCurrentMenuItem] = useState(locState.menuItem.id.toString());
useEffectOnce(() => {}), [];
useEffect(() => {
if (reportParams?.length === 0) {
dispatch(getReportParamsAsync(currentMenuItem));
}
//reload hack in order to get page to load correct fields when navigating to another report view
if (currentMenuItem != locState.menuItem.id) {
window.location.reload();
setCurrentMenuItem(locState.menuItem.id.toString());
}
}, [dispatch, reportParams, currentMenuItem, locState, state]);
//dependency list to check for dependent dropdowns, passed to reportddl
reportParams.forEach((parameter: any) => {
if (parameter.dependencies !== null && parameter.dependencies[0] !== 'apu_id') {
depList.push(parameter);
}
});
//filter dispatched data to build correct fields with data attached.
reportParams.forEach((parameter: any, i: number) => {
if (parameter.validValuesQueryBased === true) {
if (parameter.validValues !== null && parameter.multiValue) {
const dataList: any[] = [];
parameter.validValues.map((record: { value: any; label: any }) =>
dataList.push({ id: record.value, desc: record.label }),
);
fields.push(
<span key={i} className='p-float-label col-12 mx-3 field'>
<MultiSelect
options={dataList}
name={parameter.name}
value={state[parameter.name]}
onChange={(e) => handleDdlVal(parameter.name, e.value)}
></MultiSelect>
<label className='mx-3'>{parameter.prompt.substring(0, parameter.prompt.indexOf(':'))}</label>
</span>,
);
} else if (parameter.validValues !== null) {
const dataList: any[] = [];
parameter.validValues.map((record: { value: any; label: any }) =>
dataList.push({ id: record.value, desc: record.label }),
);
fields.push(
<span key={i} className='p-float-label col-12 mx-3 field'>
<Dropdown
options={dataList}
optionValue='id'
optionLabel='desc'
name={parameter.name}
onChange={(e) => handleDdlVal(parameter.name, e.value)}
value={state[parameter.name]}
//required={parameter.parameterStateName}
placeholder={'Select a Value'}
></Dropdown>
<label className='mx-3'>{parameter.prompt.substring(0, parameter.prompt.indexOf(':'))}</label>
</span>,
);
}
} else if (parameter.parameterTypeName === 'Boolean') {
fields.push(
<span key={i} className='col-12 mx-3 field-checkbox'>
<InputSwitch
checked={state[parameter.name]}
id={parameter.id}
name={parameter.name}
onChange={(e) => handleBoolVal(parameter.name, e.value)}
></InputSwitch>
<label className='mx-3'>{parameter.prompt.substring(0, parameter.prompt.indexOf(':'))}</label>
</span>,
);
} else if (parameter.parameterTypeName === 'DateTime') {
//const date = new Date(parameter.defaultValues[0]);
fields.push(
<span key={i} className='p-float-label col-12 mx-3 field'>
<Calendar
value={state[parameter.name]}
name={parameter.name}
onChange={(e) => {
const d: Date = e.value as Date;
handleCalVal(parameter.name, d);
}}
></Calendar>
<label className='mx-3'>{parameter.prompt.substring(0, parameter.prompt.indexOf(':'))}</label>
</span>,
);
} else if (parameter.name === 'apu_id') {
return null;
} else {
fields.push(
<span key={i} className='p-float-label col-12 mx-3 field'>
<InputText name={parameter.name}></InputText>
<label className='mx-3'>{parameter.prompt.substring(0, parameter.prompt.indexOf(':'))}</label>
</span>,
);
}
});
const onSubmit = () => {
console.log(state);
};
return (
<Form onReset={null} onSubmit={onSubmit} initialValues={null} validation={null} key={null}>
{fields}
</Form>
);
};
enter code here

Access to api response data

My code pass in a search term and the promise api call returns one record and the data format is as below:
` json api data
0:
{
id:"aff3b4fa-bdc0-47d1-947f-0163ff5bea06"
keyword: somekeyword
URL:"mypage.html"
}
I need to retrieve the URL value, so I try to get URL by using response.data[0].URL. But I receive the error "Unhandled Rejection (TypeError): response.data[0] is undefined". How do I get the URL value? Thanks.
` autocomplete.js
export class Autocomplete extends Component {
state = {
activeSuggestion: 0,
filteredSuggestions: [],
showSuggestions: false,
userInput: "",
suggestions: [],
results: [],
URL: "",
};
componentDidMount() {
this.GetPrograms();
const { userInput } = this.state;
//this.runSearch();
}
GetPrograms = () => {
axios
.get("https://mydomain/GetPrograms/")
.then((response) => {
this.setState({ suggestions: response.data });
});
};
runSearch = async () => {
const response = await axios.get(
"https://mydomain/api/get",
{
params: {
searchTerm: this.state.userInput,
},
}
);
let results = response.data;
console.log("response", results);
this.setState({ results: results, URL: response.data[0].URL });
window.location.href =
"https://mydomain/" + this.state.URL;
};
onChange = (e) => {
const { suggestions } = this.state; //this.props;
const userInput = e.currentTarget.value;
const filteredSuggestions = suggestions.filter(
(suggestion) =>
suggestion.toLowerCase().indexOf(userInput.toLowerCase()) > -1
);
this.setState({
activeSuggestion: 0,
filteredSuggestions,
showSuggestions: true,
userInput: e.currentTarget.value,
});
};
onClick = (e) => {
this.setState({
activeSuggestion: 0,
filteredSuggestions: [],
showSuggestions: false,
userInput: e.currentTarget.innerText,
});
this.onSearch();
console.log(
"child component clicked and value=" + e.currentTarget.innerText
);
};
onKeyDown = (e) => {
const { activeSuggestion, filteredSuggestions } = this.state;
if (e.keyCode === 13) {
this.setState({
activeSuggestion: 0,
showSuggestions: false,
userInput: filteredSuggestions[activeSuggestion],
});
} else if (e.keyCode === 38) {
if (activeSuggestion === 0) {
return;
}
this.setState({ activeSuggestion: activeSuggestion - 1 });
} else if (e.keyCode === 40) {
if (activeSuggestion - 1 === filteredSuggestions.length) {
return;
}
this.setState({ activeSuggestion: activeSuggestion + 1 });
}
//this.setState({ searchTerm: e.currentTarget.value });
console.log("userinput:" + this.state.userInput);
};
render() {
const {
onChange,
onClick,
onKeyDown,
onKeyPress,
state: {
activeSuggestion,
filteredSuggestions,
showSuggestions,
userInput,
},
} = this;
let suggestionsListComponent;
if (showSuggestions && userInput) {
if (filteredSuggestions.length) {
suggestionsListComponent = (
<ul class="suggestions">
{filteredSuggestions.map((suggestion, index) => {
let className;
if (index === activeSuggestion) {
className = "";
}
return (
<li key={suggestion} onClick={onClick}>
{suggestion}
</li>
);
})}
</ul>
);
} else {
suggestionsListComponent = (
<div class="no-suggestions">
<em>No suggestions</em>
</div>
);
}
}
return (
<div>
<input
id="search-box"
placeholder="Search..."
type="search"
onChange={onChange}
onKeyDown={onKeyDown}
value={userInput}
/>
{suggestionsListComponent}
</div>
);
}
}
export default Autocomplete;
`
The api call returns 0 record that causes the error.

How to properly display JSON result in a table via ReactJS

I have this code which fetches data from an API and displays JSON response in a div. How do I display the JSON response in a table?
This is how I display it in div via status.jsx:
// some codings
render() {
const { status, isLocal } = this.props;
if(!isLocal()) {
return (
<div className="status">
<div className="status-text">
<b>Status</b> {status.text}<br />
<b>Title</b> status.textTitle} <br />
<b>Event</b> {status.textEvent}
</div>
</div>
)
}
}
I have tried displaying it in a table as per below but could not get it to be aligned properly
//some codings
render() {
const { status, isLocal } = this.props;
if(!isLocal()) {
return (
<table>
<tbody>
<th>Status</th>
<th>Title</th>
<th>Event</th>
<tr>
<td>{status.text} </td>
<td>{status.textTitle} </td>
<td>{status.textEvent}</td>
<td><button
className="btn btn-danger status-delete"
onClick={this.toggleDeleteConfirmation}
disabled={this.state.showDeleteConfirmation}
>
Delete
</button></td>
</tr></tbody>
</table>
)
}
}
Here is profile.jsx:
import React, { Component } from 'react';
import {
isSignInPending,
loadUserData,
Person,
getFile,
putFile,
lookupProfile
} from 'bs';
import Status from './Status.jsx';
const avatarFallbackImage = 'https://mysite/onename/avatar-placeholder.png';
const statusFileName = 'statuses.json';
export default class Profile extends Component {
constructor(props) {
super(props);
this.state = {
person: {
name() {
return 'Anonymous';
},
avatarUrl() {
return avatarFallbackImage;
},
},
username: "",
statuses: [],
statusIndex: 0,
isLoading: false
};
this.handleDelete = this.handleDelete.bind(this);
this.isLocal = this.isLocal.bind(this);
}
componentDidMount() {
this.fetchData()
}
handleDelete(id) {
const statuses = this.state.statuses.filter((status) => status.id !== id)
const options = { encrypt: false }
putFile(statusFileName, JSON.stringify(statuses), options)
.then(() => {
this.setState({
statuses
})
})
}
fetchData() {
if (this.isLocal()) {
this.setState({ isLoading: true })
const options = { decrypt: false, zoneFileLookupURL: 'https://myapi/v1/names/' }
getFile(statusFileName, options)
.then((file) => {
var statuses = JSON.parse(file || '[]')
this.setState({
person: new Person(loadUserData().profile),
username: loadUserData().username,
statusIndex: statuses.length,
statuses: statuses,
})
})
.finally(() => {
this.setState({ isLoading: false })
})
} else {
const username = this.props.match.params.username
this.setState({ isLoading: true })
lookupProfile(username)
.then((profile) => {
this.setState({
person: new Person(profile),
username: username
})
})
.catch((error) => {
console.log('could not resolve profile')
})
const options = { username: username, decrypt: false, zoneFileLookupURL: 'https://myapi/v1/names/'}
getFile(statusFileName, options)
.then((file) => {
var statuses = JSON.parse(file || '[]')
this.setState({
statusIndex: statuses.length,
statuses: statuses
})
})
.catch((error) => {
console.log('could not fetch statuses')
})
.finally(() => {
this.setState({ isLoading: false })
})
}
}
isLocal() {
return this.props.match.params.username ? false : true
}
render() {
const { handleSignOut } = this.props;
const { person } = this.state;
const { username } = this.state;
return (
!isSignInPending() && person ?
<div className="container">
<div className="row">
<div className="col-md-offset-3 col-md-6">
{this.isLocal() &&
<div className="new-status">
Hello
</div>
}
<div className="col-md-12 statuses">
{this.state.isLoading && <span>Loading...</span>}
{
this.state.statuses.map((status) => (
<Status
key={status.id}
status={status}
handleDelete={this.handleDelete}
isLocal={this.isLocal}
/>
))
}
</div>
</div>
</div>
</div> : null
);
}
}

Edit action in react-redux

I am trying to perform an edit action in react-redux. First, I created a button on the index page.
<Link to = {`/standups/${list.id}`}>Edit</Link>
When I clicked on this button, it went to the edit page but no data was present.
In my edit page, I have this code:
class StandupEdit extends Component {
constructor(props){
super(props);
this.state = {
standups: {
user_id: this.props.standup ? this.props.standup.user_id : '',
day: this.props.standup ? this.props.standup.day : '',
work_done: this.props.standup ? this.props.standup.work_done : '',
work_planned: this.props.standup ? this.props.standup.work_planned : '',
blocker: this.props.standup ? this.props.standup.blocker : ''
},
submitted: false
};
}
handleSubmit = (event) => {
event.preventDefault();
const { standups } = this.state;
const { dispatch } = this.props;
if(standups.work_done && standups.work_planned && standups.blocker) {
dispatch(addStandup(this.state.standups))
} else {
this.setState({
submitted: true
})
}
}
componentWillReceiveProps = (nextProps) => {
debugger
this.setState({
standups: {
user_id: nextProps.user_id,
day: nextProps.day,
work_done: nextProps.work_done,
work_planned: nextProps.work_planned,
blocker: nextProps.blocker
}
});
}
componentDidMount(){
if(this.props.match.params.id){
this.props.editStandup(this.props.match.params.id)
}
}
handleChange = (event) => {
const {name, value} = event.target;
const {standups} = this.state;
this.setState({
standups: {
...standups,
[name]: value
}
});
}
render() {
const {standups, submitted, fireRedirect} = this.state
return (
<MuiThemeProvider theme={theme}>
<Paper>
<h1 className='header'>Add new standup</h1>
</Paper>
<Grid container spacing={16}>
<form onSubmit={this.handleSubmit}>
<Paper className='form'>
<TextField fullWidth name= "work_done"
value = {standups.work_done}
onChange= {this.handleChange}
type= "text"
placeholder= "What did you work on yesterday?"/>
{
submitted && !standups.work_done ?
<p>Work done is required</p> : ''
}
</Paper>
<Paper className='form'>
<TextField fullWidth name= "work_planned"
value = {standups.work_planned}
onChange= {this.handleChange}
type= "text"
placeholder= "What are you planning to work on today?"/>
{
submitted && !standups.work_planned ?
<p>Work planned is required</p> : ''
}
</Paper>
<Paper className='form'>
<TextField fullWidth name= "blocker"
value = {standups.blocker}
onChange= {this.handleChange}
type= "text"
placeholder= "Any impediments in your way?"/>
{
submitted && !standups.blocker ?
<p>Blocker required</p> : ''
}
</Paper>
<div className='button'>
<Button type="submit">Update</Button>
</div>
</form>
</Grid>
</MuiThemeProvider>
);
}
}
function mapStateToProps(state, props){
if (props.match.params.id) {
return {
standup: state.standup.standups.findIndex(item => item.id === props.match.params.id)
}
}
return {
standup: null
}
}
export default connect(mapStateToProps, {editStandup})(StandupEdit);
In action, I have this code:
export function editStandup(id) {
return dispatch => {
axios(`${ROOT_URL}/standups/${id}/${API_KEY}`, {
headers: authHeader(),
method: 'GET',
}).then( response => {
dispatch(success(response.data.standup))
})
}
function success(response) {
return {
type: 'STANDUP_EDIT',
payload: response
}
}
}
export function updateStandup(standup) {
const request = axios({
headers: authHeader(),
method: 'PUT',
url: `${ROOT_URL}/standups${API_KEY}`,
data: standup
})
return {
type: 'STANDUP_UPDATE',
payload: request
}
}
And I have following code in my reducer:
export function standup(state = {}, action){
switch (action.type) {
case 'STANDUP_UPDATE':
return state.map(item => {
if(item.id === action.payload.id)
return
standup: action.payload
return item;
});
case 'STANDUP_EDIT':
const index = state.standups.findIndex(item => item.id === action.payload.id);
if (index > -1){
return state.standups.map(item => {
if(item.id === action.payload.id)
return action.payload
});
}else{
return
standup: action.payload
}
default:
return state;
}
}
In my reducer findIndex(item => item.id === action.payload.id);, item => item.id contain error item.id is undefined.
Will anyone help me in solving this problem?
You aren't updating the state in reducer correctly, standups is not defined initially which you must do. Check the same code below
export function standup(state = {standups: []}, action){
switch (action.type) {
case 'STANDUP_UPDATE': {
const index = state.standups.findIndex(item => item.id === action.payload.id);
return {
...state,
standups: {
...state.standups.slice(0, index),
action.payload,
...state.standups.slice(index + 1),
}
}
}
case 'STANDUP_EDIT':
const index = state.standups.findIndex(item => item.id === action.payload.id);
if (index > -1){
return {
...state,
standups: {
...state.standups.slice(0, index),
action.payload,
...state.standups.slice(index + 1),
}
}
}
return {
...state,
standups: {
...state.standups
action.payload,
}
default:
return state;
}
}
Also your component name is StandupEdit and you are connecting StandupNew with the connect function
export default connect(mapStateToProps, {editStandup})(StandupEdit);

Resources