I have react hooks section in which user can edit input fields, there are hundreds of inputs that is why I need to use redux (newbie to redux though),
Live demo on codesandbox: demo
so far I have this
const initialState = {
firstName: "Kunta ",
lastName: "Kinte"
};
const detailsReducer = (state = initialState, action) => {
const { name, value } = action;
return { ...state, [name]: value };
};
export default detailsReducer;
and here is setting js where I have input fields
import React, { useState } from "react";
import { useSelector } from "react-redux";
import Details from "./Details";
import DetailsReducer from "../Reducer/DetailsReducer";
const Settings = () => {
const fields = useSelector((state) => state.DetailsReducer);
const [state, setState] = useState("");
return (
<div>
<div>
<h1>Edit </h1>
<div className="container">
<div className="inputs">
<label htmlfor="fname">First name:</label>
<input
type="text"
id="fname"
name="fname"
value={state}
onChange={(e) => setState(e.target.value)}
/>
<label htmlfor="lname" />
Last name:
<input type="text" id="lname" name="lname" onChange={(e) => setState(e.target.value)} />
</div>
<Details />
</div>
</div>
</div>
);
};
export default Settings;
Expected results: Just when the user types in inputs eg first name it should change the value of the first name in the details component.
I am strugling to get this working can some please help?