I have a datatable in my react app and when I click on "Add New" button on the datatable, I open AddNew page (a reusable form). This page reads the form fields (employeeInputs
) given on the App.js
import { employeeInputs } from "./formSource";
function App() {
return (
<div>
<BrowserRouter>
<Routes>
<Route path="/">
<Route path="employees">
<Route
path="new"
element={<AddNew inputs={employeeInputs} title="Add New" />}
/>
</Route>
</Route>
</Routes>
</BrowserRouter>
</div>
);
}
export default App;
My question: If I use this approach, I can define new form fields for the other records e.g. Department, Salary … and read fields in here by adding reference as:
import { employeeInputs } from "./formSource";
However, should I pass this parameter (name or the input, e.g. "employeeInputs") from the Datatable where I call this form? Otherwise, I do not make my App.js dirty with unnecesaary code. Any idea?
2
Answers
I got this issue and fixed it with the pass state in
Link
component ofreact-router-dom
.First of all you can split your app components into body header and footer
your new body components will look like
your header component will contain your navigation bar
you footer is your footer ,
otherwise it depend on what is exactly your employeeInputs