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.j
s 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.