- Forums
- react
- React Import and Export a Single Function From a Components File Form Fields Example
This this example to create a file with only a function to be use in different components in a react application. [5180], Last Updated: Mon Jun 24, 2024
react
Mon Aug 14, 2023
0 Comments
231 Visits
Import functiom from component file.
Create FormFields.jsx file
1. create file: components > utilities > FormFields.jsx
$ touch src/components/utilities/FormFields.jsx
2. Add the following code
export const GenerateForm = (parameter) => {
// do something
return parameter;
}
Usage:
Import:
import { GenerateForm } from "/src/components/utitlies/FormFields";
Call Function
const example = GenerateForm (parameter);
There are times when you just need to create a component that only has a function so other components can use by calling it and processing the code with a parameter. This is how you do it.