I have this React component that I am trying to build. addEntry detects when the user submits a data entry, and RenderTable should render each entry in a table row format:
import React, { useState, setState } from 'react';
import ReactDOM from 'react-dom'function
function addEntry({ addEntryData }) {
const data = [{
First: "aaa",
Last: "bbb",
Phone: 123123
}];
const [contact, setContact] = useState(data);
const submitEntry = (e) => {
e.preventDefault();
setContact(contact.push({
First: e.target.userFirstname.value,
Last: e.target.userLastname.value,
Phone: e.target.userPhone.value
}))
}
return (
<form onSubmit={submitEntry} style={style.form.container}>
<input
className='userFirstname'
name='userFirstname'
type='text'
/>
<input
className='userLastname'
name='userLastname'
type='text'
/>
<input
className='userPhone'
name='userPhone'
type='text'
/>
<input
className='submitButton'
type='submit'
value='Add User'
/>
</form>
)
};
function RenderTable(props) {
return (
<table className='informationTable'>
<thead>
<tr>
<th style={style.tableCell}>First name</th>
<th style={style.tableCell}>Last name</th>
<th style={style.tableCell}>Phone</th>
</tr>
</thead>
</table>
);
}
function Application(props) {
return (
<section>
<addEntry/>
<RenderTable/>
</section>
);
I would like to pass the contact data from addEntry to RenderTable, so RenderTable could generate some rows. But I have tried props or calling RenderTable(contact). Contact seems to live only inside addEntry, and not RenderTable. What should I do such that RenderTable could read the values stored in the contact variable?