React Bootstrap Textarea in Form Example

React Bootstrap Textarea in Form Example

React-bootstrap textarea value example; In this tutorial, you will learn how to use bootstrap textarea with set value in state with react js apps.

How to use React Bootstrap Textarea in Form

Here are steps to use bootstrap textarea:

Step 1 – Create React App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app my-react-app

To run the React app, execute the following command on your terminal:

npm start

Check out your React app on this URL: localhost:3000

Step 2 – Install and Set up Bootstrap

Run the following command to install react bootstrap library into your react app:

npm install bootstrap --save

npm install react-bootstrap bootstrap

Set up bootstrap.min.css file in src/App.js file:

import React, { Component } from 'react'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
function App() {
return (
<div>
<h2>How to refresh a Page in React</h2>
</div>
);
}
export default App;

Step 3 – Create TextArea Component

Create BootstrapTextarea.js file in src directory and inside this file, add the textarea field:

import React from 'react'
import Form from 'react-bootstrap/Form'
class BootstrapTextarea extends React.Component{
constructor(){
super();
this.state = {
address:null
}
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
this.setState({
address: event.target.value
});
console.warn(this.state)
}
render(){
return(
<div>
<Form>
<Form.Group controlId="exampleForm.ControlTextarea1">
<Form.Label>Example textarea</Form.Label>
<Form.Control as="textarea" rows="3" name="address" onChange={this.handleInputChange} />
</Form.Group>
</Form>
</div>
)
}
}
export default BootstrapTextarea;

Step 4 – Import TextArea Component in App.js

In this step, you need to add BootstrapTextarea.js file in src/App.js file:

import React from 'react';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import BootstrapTextarea from './BootstrapTextarea'
function App() {

return (
<div className="App">
<BootstrapTextarea />
</div>
);
}
export default App;

Conclusion

In this tutorial, you have learned how to use bootstrap textarea with set value in state with react js apps.

Recommended React JS Posts

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *