Modify prop in list of components generated in a loop - reactjs

I have a checkbox component that has a disabled property. My goal is:
When 3 checkboxes are selected set the disabled property to true in all checkboxes that are not selected.
Each time a checkbox is selected show an updated count of remaining selection allowed.
For goal 1 I am not sure what the right way to do this is. Do I need to create an array of refs?
For goal 2 I have added this code:
{3 - Object.keys(selected).length + " domains remaining"}
But when selected is updated the render does not get the updated value.
My code with comment where I want to disable/enable all is on codesandbox here: https://codesandbox.io/s/exciting-bush-119ef?file=/src/App.js
Also pasted here below:
import React, { useState } from "react";
export default function App(props) {
const [enableSelection, setEnableSelection] = useState(true);
const [selected, setSelected] = useState({});
let domains = [
"example1.com",
"example2.com",
"example3.com",
"example4.com",
"example5.com",
"example6.com",
"example7.com",
"example8.com",
"example9.com",
"example10.com",
"example11.com",
"example12.com",
"example13.com",
"example14.com",
"example15.com",
"example16.com"
];
function handleChange(index, event) {
console.log(index);
console.log(event.target.name);
console.log(event.target.value);
console.log(event.target.checked);
if (event.target.checked === true) {
setSelected((prev) => {
prev[index] = event.target.value;
return prev;
});
} else {
setSelected((prev) => {
delete prev[index];
return prev;
});
}
if (Object.keys(selected).length >= 3) {
//disable all other input
} else {
//make sure all other enabled
}
}
return (
<div className="">
<div className="">
<SubHead
text={3 - Object.keys(selected).length + " domains remaining"}
/>
{domains.map((domain, i) => (
<div key={i} className="odd:bg-gray-200">
<CheckBox
disabled={false}
label={domain}
name={"checkbox_" + i}
value={domain}
onChange={(index, e) => handleChange(i, e)}
/>
</div>
))}
</div>
</div>
);
}
function CheckBox({
disabled,
key,
label,
selected,
name,
value,
onChange: parentChange
}) {
const [selectedState, setSelectedState] = useState(selected ?? false);
function handleChange(event) {
setSelectedState(!selectedState);
parentChange(key, event);
}
return (
<label key={key} className="inline-flex items-center mt-3">
<input
id={name}
name={name}
value={value}
onChange={handleChange}
type="checkbox"
className="form-checkbox h-5 w-5 text-gray-600"
disabled={disabled}
checked={selected}
/>
<span
className={
"ml-2 " +
(selectedState ? "font-semibold " : "") +
(disabled ? "text-gray-400" : "text-gray-700")
}
>
{label}
</span>
</label>
);
}
function SubHead(props) {
return <h3 className="font-medium text-xl text-center">{props.text}</h3>;
}

The problem was that you handle the event in two places,
You don't need to handle the state of the checkbox twice, once in the parent and another inside it. I also converted the selected to array to make it easier:
Here is the demo: https://codesandbox.io/s/boring-sun-35lfk?file=/src/App.js
import React, { useState } from "react";
export default function App(props) {
const [selected, setSelected] = useState([]);
let domains = [
"example1.com",
"example2.com",
"example3.com",
"example4.com",
"example5.com",
"example6.com",
"example7.com",
"example8.com",
"example9.com",
"example10.com",
"example11.com",
"example12.com",
"example13.com",
"example14.com",
"example15.com",
"example16.com"
];
function handleChange(event) {
console.log(event.target.name);
console.log(event.target.value);
console.log(event.target.checked);
if (event.target.checked) {
setSelected((prev) => [...prev, event.target.name]);
} else {
setSelected((prev) => prev.filter((name) => name !== event.target.name));
}
if (Object.keys(selected).length >= 3) {
//disable all other input
} else {
//make sure all other enabled
}
}
const remaining = 3 - Object.keys(selected).length;
return (
<div className="">
<div className="">
<SubHead text={remaining + " domains remaining"} />
{domains.map((domain) => {
const checked = selected.indexOf("checkbox_" + domain) > -1;
return (
<div key={domain} className="odd:bg-gray-200">
<CheckBox
checked={checked}
disabled={!checked && remaining === 0}
label={domain}
name={"checkbox_" + domain}
value={domain}
onChange={handleChange}
/>
</div>
);
})}
</div>
</div>
);
}
function CheckBox({
checked,
disabled,
key,
label,
selected,
name,
value,
onChange: parentChange
}) {
return (
<label key={key} className="inline-flex items-center mt-3">
<input
id={name}
name={name}
value={value}
onChange={parentChange}
type="checkbox"
className="form-checkbox h-5 w-5 text-gray-600"
disabled={disabled}
checked={selected}
/>
<span
className={
"ml-2 " +
(checked ? "font-semibold " : "") +
(disabled ? "text-gray-400" : "text-gray-700")
}
>
{label}
</span>
</label>
);
}
function SubHead(props) {
return <h3 className="font-medium text-xl text-center">{props.text}</h3>;
}

Related

How can I maintain the order of adding items in react web app?

How can I create an order of adding items. I should be able to add one after the other item during on click. By default it should display the Textarea first and then blockquote ( see below )
a) When a user click on Text area button, it should add one after the blockquote.
b) Then when the user clicks on Code area button, it should add after Textarea. Could someone please advise ?
CSB link: https://codesandbox.io/s/distracted-worker-26jztf?file=/src/App.js
Something similar >> Expected behaviour: https://jsfiddle.net/nve8qdbu/8/
import "./styles.css";
import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useForm } from "react-hook-form";
const blogListData = [
{
id: 1,
heading: "React state",
date: "22-May-2022",
tag: "React",
count: "3"
},
{
id: 2,
heading: "Cypress testing detailss",
date: "22-May-2022",
tag: "Cypress",
count: "5"
}
];
const Admin = () => {
const [createImageTag, setImageTag] = useState("");
const [fields, setFields] = useState([{ value: null }]);
const [createCode, setCreateCode] = useState([{ value: null }]);
const [blogList, setBlogList] = useState([]);
const {
register,
handleSubmit,
formState: { errors },
reset
} = useForm();
useEffect(() => {
setBlogList(blogListData);
}, []);
function handleChangeTextArea(i, event) {
const values = [...fields];
values[i].value = event.target.value;
setFields(values);
}
function handleChangeCode(i, event) {
const codeValues = [...createCode];
codeValues[i].value = event.currentTarget.innerText;
setCreateCode(codeValues);
}
function handleTextAreaAdd() {
const values = [...fields];
values.push({ value: null });
setFields(values);
}
function handleCodeAreaAdd() {
const codeValues = [...createCode];
codeValues.push({ value: null });
setCreateCode(codeValues);
}
function handleImageAreaAdd() {
const image = [...createImageTag];
image.push({ value: null });
setCreateCode(image);
}
function handleRemoveText(i) {
const values = [...fields];
values.splice(i, 1);
setFields(values);
}
function handleRemoveCode(i) {
const codeValues = [...createCode];
codeValues.splice(i, 1);
setCreateCode(codeValues);
}
const handleLogout = () => {
localStorage.removeItem("loginEmail");
};
return (
<div id="App">
<div className="parent">
<div className="adminSection">
<h1>Create a new blog</h1>
<div className="row">
<div className="logout">
<img
src="/images/logout.png"
alt="Logout"
onClick={handleLogout}
></img>
</div>
<div className="createBlogSection">
<div className="row">
<button
onClick={() => handleTextAreaAdd()}
className="textAreaBtn"
>
Text Area
</button>
<button
onClick={() => handleCodeAreaAdd()}
className="codeAreaBtn"
>
Code Area
</button>
<button
onClick={() => handleImageAreaAdd()}
className="imageAreaBtn"
>
Add Image
</button>
</div>{" "}
<br></br>
<div className="row">
{fields.map((field, idx) => {
return (
<div key={`${field}-${idx}`} className="dtextArea">
<button
type="button"
onClick={() => handleRemoveText(idx)}
className="closeElement"
>
X
</button>
<textarea
type="text"
id="blogtext"
placeholder="Enter your text here"
className="defaultTextArea"
{...register("blogtext", {
required: true,
minLength: {
value: 25,
message: "Minimum length of 25 letters"
}
})}
value={field.value || ""}
onChange={(e) => handleChangeTextArea(idx, e)}
/>
<span className="validationmsg">
{errors.blogtext &&
errors.blogtext.type === "required" && (
<span>Blog text is required !</span>
)}
{errors.blogtext && (
<span>{errors.blogtext.message}</span>
)}
</span>
</div>
);
})}
</div>
<div className="row">
{createCode.map((code, idx) => {
return (
<div key={`${code}-${idx}`} className="dCodeArea">
<button
type="button"
onClick={() => handleRemoveCode(idx)}
className="closeElement"
>
X
</button>
<blockquote
type="text"
id="blogCode"
contentEditable="true"
className="codehighlight"
placeholder="Enter your code here"
{...register("blogCode", {
required: true
})}
value={code.value || ""}
onInput={(e) => handleChangeCode(idx, e)}
/>
</div>
);
})}
</div>
<div className="row">
</div>
<div className="row">
<div className="submitSection">
<input type="submit" className="submitBtn" />
</div>
</div>
</div>
</div>
</div>
<div className="blogListSection">
<h1>Edit blogs</h1>
<div className="row">
<div className="editBlogSection">
{blogList.map(({ id, heading, count }) => (
<a
key={id}
href="https://www.testingsite.com/"
className="blogitems"
>
<pre>
<span>{count}</span> {heading}
</pre>
</a>
))}
</div>
</div>
</div>
</div>
</div>
);
};
export default Admin;
react is designed for components . each of your list elements should be refactored by a component.then it would be easier. i think a single react component could do the trick

Auto Checked the Checkbox based on the data in database when Editing the data react, inertia , laravel

I need to auto-check the checkbox based on the data stored in the database. I'm trying to check the checkbox of the list of permissions given to the specified role when I try to edit the specified role, so the user doesn't need to add the permissions from zero. I'm using Laravel as the backend and Reactjs for the front end also Inertiajs as the bridge. I have no idea how to solve this.
I was able to retrieve the data from the controller which is included the specified role and the permission. I just need to auto-check the checkbox based on the data when user jump to edit feature.
export default function EditPermission(props) {
const { role } = usePage().props
const { data, setData, put, processing, errors, reset } = useForm({
name: role.name || '',
permissions: role.permissions || ''
})
const onHandleChange = event => {
setData(event.target.name, event.target.type === 'checkbox' ? event.target.checked : event.target.value)
}
const handleChecked = e => {
let value = e.target.name
if (e.target.checked) {
setData("permissions", [...data.permissions, value])
} else {
setData(
"permissions",
data.permissions.filter(item => {
return item !== value
})
)
}
}
const submit = (e) => {
e.preventDefault()
put(route('role.update', permission.id))
}
return (
<AuthenticatedLayout auth={props.auth} errors={props.errors}>
<div className="w-full lg:max-w-6xl mt-6 px-6 py-4 bg-white shadow-md overflow-hidden sm:rounded-lg">
{props.flash.message !== null ? <Flash message={props.flash.message} /> : <div></div>}
<form onSubmit={submit}>
<div>
<InputLabel forInput="name" value="Role" />
<TextInput
type="text"
name="name"
value={data.name}
className="m-2 input input-bordered w-full"
autoComplete="name"
isFocused={true}
handleChange={onHandleChange}
/>
<InputError message={errors.name} className="mt-2" />
<div class="grid grid-cols-5 gap-4">
{ props.permissions && props.permissions.length > 0 ? props.permissions.map((permissions, i) => {
return (
<div>
<Checkbox name={permissions.name} value={data.permissions} handleChange={handleChecked} />{permissions.name}
</div>
)}) : <p>Permission Belum Ada!</p>
}
</div>
<InputError message={errors.permissions} className="mt-2" />
<PrimaryButton className="ml-4" processing={processing}>
Update
</PrimaryButton>
</div>
</form>
</div>
</AuthenticatedLayout>
)
}

react simple keyboard not able to type in multiple input

I have following code of Calculator.jsx where everything looks fine.The main thing I want to achieve is keyboard to displayed only on input click which is done but the keyboard does not seem to type though the following code looks fine. Are there any other way to show/hide keyboard only on input click as well as make keyboard be able to type. My code for Calculator.jsx is
Calculator.jsx
import React, { useState, useRef, useEffect } from 'react';
import './Calculator.css'
import { Link } from 'react-router-dom';
import Keyboard from "react-simple-keyboard";
import "react-simple-keyboard/build/css/index.css";
const Calculator = () => {
const [inputs, setInputs] = useState({});
const [layoutName, setLayoutName] = useState("default");
const [inputName, setInputName] = useState("default");
const keyboard = useRef();
const [keyboardVisibility, setKeyboardVisibility] = useState(false);
useEffect(() => {
function clickHanlder(e) {
if (
!(e.target.nodeName === "INPUT") &&
!e.target.classList.contains("hg-button") &&
!e.target.classList.contains("hg-row")
) {
setKeyboardVisibility(false);
}
}
window.addEventListener("click", clickHanlder);
return window.removeEventListener("click", clickHanlder, true);
}, []);
const onChangeAll = inputs => {
setInputs({ ...inputs });
console.log("Inputs changed", inputs);
};
const handleShift = () => {
const newLayoutName = layoutName === "default" ? "shift" : "default";
setLayoutName(newLayoutName);
};
const onKeyPress = button => {
console.log("Button pressed", button);
if (button === "{shift}" || button === "{lock}") handleShift();
};
const onChangeInput = event => {
const inputVal = event.target.value;
setInputs({
...inputs,
[inputName]: inputVal
});
keyboard.current.setInput(inputVal);
};
const getInputValue = inputName => {
return inputs[inputName] || "";
};
return (
<div>
<div className="bg">
<div className="deposit">
<div className="header">
<h1>Deposit Calculator</h1>
<div className="form">
<form className="calculator">
<div className="form-group">
<label for="depositAmount">Deposit Amount:</label>
<span className="rupees">Rs</span>
<input className="IInput"
type="text"
name='depositAmount'
placeholder='0'
value={getInputValue("depositAmount")}
onChange={onChangeInput}
onFocus={() => {
setKeyboardVisibility(true);
setInputName("depositAmount")
}}
/>
</div>
<div className="form-group">
<label for="interestRate">Interest Rate:</label>
<input className= "IIinput"
type="text"
name='Interest'
placeholder='0'
value={getInputValue("interestRate")}
onChange={onChangeInput}
onFocus={() => {
setKeyboardVisibility(true);
setInputName("interestRate")
}}
/>
<span className= "percent">%</span>
</div>
<div class="form-group">
<label for="Tenure">Tenure:</label>
<input className="Input"
type='number'
min='1'
max='5'
name='tenure'
placeholder='1 year'
value={getInputValue("tenure")}
onChange={onChangeInput}
onFocus={() => {
setKeyboardVisibility(true);
setInputName("tenure")
}}
/>
</div>
{ keyboardVisibility && (
<Keyboard
keyboardRef={(r) => (keyboard.current = r)}
layoutName={layoutName}
onChange={onChangeAll}
onKeyPress={onKeyPress}
/>
)}
</form>
<button className="calculate">Calculate
</button>
</div>
<div className="given">
<p >
Total Deposit: Rs 0
</p>
<p>
Interest: Rs 0
</p>
<p>
Maturity Amount: Rs 0
</p>
</div>
</div>
</div>
</div>
<Link to="/">
<button className="Back">
<i class="fas fa-angle-double-left"></i>
</button>
</Link>
</div>
);
};
export default Calculator;
You are setting the inputs state by spreading input string from keyboard onChangeAll into an object setInputs({ ...inputs }). If I enter ab it will set as {0: "a", 1:"b"}.
Update the onChange prop in Keyboard to onChangeAll and pass inputName prop with your inputName state value. Read react-simple-keyboard DOCS.
onChangeAll
const onChangeAll = (inputs) => {
console.log("Inputs changed", inputs);
setInputs(inputs);
};
Keyboard
{keyboardVisibility && (
<Keyboard
keyboardRef={(r) => (keyboard.current = r)}
layoutName={layoutName}
onChangeAll={onChangeAll}
onKeyPress={onKeyPress}
inputName={inputName}
/>
)}
CodeSandbox link

React prop value changing though it is readonly

I have a parent component - RoomSettings.tsx where I am passing a prop, room to a child component RoomSettingsStreams
RoomSettings.tsx
export default function RoomSettings() {
const { id } = useParams() as { id: string };
const [room, setRoom] = useState<Room | null>({
streams: [
{
name: "Somthing",
other: "Others",
},
{
name: "Somtehing 2",
others: "Sasdfasd",
},
],
});
return (
<div className="h-screen flex overflow-hidden bg-slate">
<RoomSettingsStreams initStreams={room ? [...room.streams] : []} />
</div>
);
}
RoomSettingStreams.tsx
interface RoomSettingsStreamsProps {
initStreams: Stream[] | null;
}
interface Stream {
name: string;
other: string;
}
export default function RoomSettingsStreams({
initStreams,
}: RoomSettingsStreamsProps) {
const [init, setInit] = useState<Stream[]>([]);
const [streams, setStreams] = useState<Stream[]>([]);
const [token, setToken] = useState("");
const [edit, setEdit] = useState(false);
const [message, setMessage] = useState({
message: "",
show: false,
type: "error",
});
const editRoom = () => {};
useEffect(() => {
if (initStreams) {
setStreams([...initStreams]);
setInit([...initStreams]);
}
}, [initStreams]);
return (
<div className="bg-card rounded-lg border border-gray-800">
{streams.map((e, i) => {
return (
<div className="p-6 pb-10 sm:mt-5 space-y-6 sm:space-y-5" key={i}>
<div className="flex">
<StreamLabel text={`Stream ${i + 1}`} />
</div>
{/* Item */}
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start">
<div>
<SettingsLabel text="Stream Title" />
</div>
<div className="mt-2 sm:mt-0 col-span-2">
{edit ? (
<Input
className="text-gray-200"
type="text"
placeholder="Enter stream title"
value={e.stream_title}
onChange={(f) => {
const newStreams = streams.map((e, j) => {
if (i === j) e.name = f.currentTarget.value;
return e;
});
setStreams([...newStreams]);
}}
/>
) : (
<p className="text-gray-200">{e.name}</p>
)}
</div>
<div className="mt-1 sm:mt-0 sm:col-span-2"></div>
</div>
{/* Item */}
<div className="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start">
<div>
<SettingsLabel text="Publishing Method" />
</div>
<div className="mt-2 sm:mt-0 col-span-2">
{edit ? (
<Listbox
options={["OBS-WebRTC", "Browser", "RTMP"]}
selected={e.other}
setSelected={(f: any) => {
const newStreams = streams.map((e, j) => {
if (i === j) e.other = f;
return e;
});
setStreams([...newStreams]);
}}
/>
) : (
<p className="text-gray-200">{e.publishing_method}</p>
)}
</div>
{/* OBS-WebRTC Keys */}
<SettingsLabel text="OBS Stream Name" />
<div className="mt-1 sm:mt-0 sm:col-span-2">
<InputClipboard
className="text-blue-brand"
type="text"
placeholder=""
value={e.name}
onClick={() => {
navigator.clipboard.writeText(e.name);
}}
readOnly={true}
/>
</div>
</div>
</div>
);
})}
<div className="p-6">
<AddItem text="Add another stream" />
</div>
<RoomSettingsEditButton
edit={edit}
setEdit={setEdit}
onCancel={() => {
setEdit(false);
if (!init) return;
setStreams([...init]);
}}
onSuccess={async () => {
editRoom();
setEdit(false);
}}
/>
</div>
);
}
When I am calling setStreams in RoomSettingsStreams.tsx it changes the value of the prop initStreams as well as the state variable init. I am using the spread operator so that there is no referential equality and I have checked with streams === initStreams which returns false but still the change in streams is reflected in the initStreams prop, any ideas how can I prevent it and what am I doing wrong?

How to get Redux Dynamic form values without specifying the name

I am generating my form by JSON data. Form rendering is working fine. Now i want to get the form values on submit something like below.So that i can call an API to save those values in the same submit event.
{"elementname1":"value1",
"elementname2":"value2"
"elementname2":"value2"}
Is there any way to get the values like that .
i have tried with formValueSelector but we have to specify the element name to get the value.
Here is my code
import React, { Component } from 'react';
import { connect } from 'react-redux'
import { getTemplateData } from './actions';
import autoBind from 'react-autobind';
import { Scrollbars } from 'react-custom-scrollbars';
import { getFormValues, Field, reduxForm } from 'redux-form';
import { formValueSelector } from 'redux-form';
function mapDispatchToProps(dispatch) {
return {
loadData() {
return dispatch(getTemplateData())
}
}
}
function mapStateToProps(state,ownProps) {
const selector = formValueSelector('create-template-form')
return {
...state,
templateData: state.templateData
}
}
class createTemplate extends Component {
constructor(props, context) {
super(props, context);
autoBind(this);
this.state = {
topTabSelected: "details",
leftTabSelected: "details",
tabIndex: 0,
dataIndex: 0
};
this.gotoGenRulesState = this.gotoGenRulesState.bind(this);
}
gotoGenRulesState = (data) => {
this.props.dispatch({ type: 'FORM_SUBMITTED',data});
}
componentDidMount() {
this.props.loadData();
}
render() {
const renderField = ({ field, detailType}) => {
const { type, placeholder } = field[detailType];
if (type === 'text' || type === 'email' || type === 'number' || type === 'checkbox') {
return <input name={detailType + field.key} {...field.input} className="form-control" placeholder={placeholder} type={type} />
} else if (type === 'select') {
const { options } = field
return (
<select name={field.name} className="form-control" onChange={field.input.onChange}>
{options.map((option, index) => {
return <option key={index} value={option.value}>{option.label}</option>
})}
</select>
)
} else {
return <div>Type not supported.</div>
}
}
return (
<form onSubmit={this.gotoGenRulesState}>
<div>
<div className="row" style={{ padding: "30px 80px" }} >
<div className="padding-sides-none col-md-12">
<h3 className="purple-color">Create Template</h3>
<div className="tabbable">
{this.props.templateData &&
<ul className="nav nav-tabs tab-nav toptab">
{this.props.templateData.map((data, index) => (
<li className={`${data.key === this.state.topTabSelected ? 'active' : ''}`} key={data.key + index} style={{ cursor: 'pointer' }} ><a onClick={() => this.openTopTab(data.key, index)}
data-toggle="tab">{data.name}</a></li>
))}
</ul>
}
<div className="">
{this.props.templateData && this.props.templateData[this.state.tabIndex] &&
<div className="tabbable tabs-left row">
<div className="padding-sides-none col-md-4 tab-sec">
<ul className="nav tab-nav">
{this.props.templateData[this.state.tabIndex].subnodes.map((data, index) => (
<li key={data.key + index} style={{ cursor: 'pointer' }} ><a className={`${data.key === this.state.leftTabSelected ? 'detailsTitleActive' : ''}`} onClick={() => this.openDetailsTab(data.key, index)}
data-toggle="tab">{data.name}</a></li>
))}
</ul>
</div>
<div className="col-md-8 padding-sides-none inner-tab-content">
<Scrollbars style={{ height: 400 }}>
<div className="tab-content">
{this.props.templateData[this.state.tabIndex].subnodes[this.state.dataIndex].subnodes.map((field, index) => (
<div className={`form-group ${field.type === 'CompleteDetail' ? 'dynamic-field-inline' : ''}`} key={field.name}>
<label>{field.name}</label>
{field.detail &&
<span>
{field.type === 'CompleteDetail' && <label>Details</label>}
<Field
name={`details${field.key}`}
component={renderField}
field={field}
detailType='detail'
/>
</span>
}
{field.range &&
<span>
{field.type === 'CompleteDetail' && <label>Range</label>}
<Field
name={'range' + field.key}
component={renderField}
field={field}
detailType='range'
/>
</span>
}
{field.operator &&
<span>
{field.type === 'CompleteDetail' && <label >Operator</label>}
<Field
name={'operator' + field.key}
component={renderField}
field={field}
detailType='operator'
/>
</span>
}
</div>
))}
</div>
</Scrollbars>
</div>
</div>
}
</div>
</div>
</div>
</div>
</div>
</form>
)
}
}
createTemplate = reduxForm({
form: 'create-template-form', // a unique identifier for this form
})(createTemplate)
createTemplate = connect(
mapStateToProps,
mapDispatchToProps
)(createTemplate)
export default createTemplate;
Using redux form you can get all form values with state.form.create-template-form.
By the way you should rename your form identifier with camelCase :
connect(
state => ({
myFormValues: state.form.createTemplateForm,
}),
)
And you will acces this value thanks to props this.props.myFormValues
If you want to use values when submitting, you can also do that :
submitFunction = (data) => {
console.log(data) // you can use your form data here, and you don't need form name
};
render() {
return (
<form onSubmit={this.props.handleSubmit(this.submitFunction)}>

Resources