Hi Team,
I need to create a simple webpart form, where the form contains a text box to user enter title values, and a button to submit the SP list row/record.
The button has to bind with the SP list to save the record from the textbox value.
also, list out the all list rows in the same webpart.
Make sure I have used REACT JS in the SPFX webpart.
any help/assistance please follow the step-by-step to create this webpart?

Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 26, 2023, 7:56 AM EDT
Step 1: Set up the development environment
npm install -g yo gulpInstall the Yeoman SharePoint generator by running the following command:
npm install -g @microsoft/generator-sharepointStep 2: Create a new SPFx project
yo @microsoft/sharepoint
Step 3: Add the form component
src/webpartsfolder.yo @microsoft/sharepoint:reactSimpleForm.tsxfile.render()method with the following code:public render(): React.ReactElement { return ( Submit {this.state.listItems.map((item) => ( {item.title} ))} ); }private readonly _listName: string = 'YourListName'; private readonly _spHttpClientOptions: ISPHttpClientOptions = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }; constructor(props: ISimpleFormProps) { super(props); this.state = { title: '', listItems: [] }; } private handleInputChange = (event: React.ChangeEvent): void => { this.setState({ title: event.target.value }); } private handleSubmit = async (): Promise => { const newItem: any = { Title: this.state.title }; const response: SPHttpClientResponse = await this.props.spHttpClient.post( `${this.props.siteUrl}/_api/web/lists/getbytitle('${this._listName}')/items`, SPHttpClient.configurations.v1, { ...this._spHttpClientOptions, body: JSON.stringify(newItem) } ); if (response.ok) { this.loadListItems(); this.setState({ title: '' }); } } private loadListItems = async (): Promise => { const response: SPHttpClientResponse = await this.props.spHttpClient.get( `${this.props.siteUrl}/_api/web/lists/getbytitle('${this._listName}')/items?$select=Id,Title`, SPHttpClient.configurations.v1, this._spHttpClientOptions ); if (response.ok) { const data: any = await response.json(); this.setState({ listItems: data.value }); } } public componentDidMount(): void { this.loadListItems(); }Step 5: Build and test the web part
gulp buildDeploy the web part to your SharePoint environment by running the following command: