Creating Form, Dialog Box and Grid UI
Creating Form, Dialog Box and Grid UI
powered by AI
2
React Components
The component also requires a render() method, this method returns HTML.
Example
render() {
return <h2>Hi, I am a Car! </h2>;
}
}
Function Component
Here is the same example as above, but created using a Function component
instead.
A Function component also returns HTML, and behaves much the same way as a
Class component, but Function components can be written using much less code,
are easier to understand, and will be preferred in this tutorial.
Example
function Car() {
}
Rendering a Component
Now your React application has a component called Car, which returns an <h2>
element.
To use this component in your application, use similar syntax as normal HTML: <Car />
Example
7
Props
Components can be passed as props, which stands for properties.
Props are like function arguments, and you send them into the component as attributes.
Example
Use an attribute to pass a color to the Car component, and use it in the render() function:
function Car(props) {
return <h2>I am a {props.color} Car!</h2>;
}
8
State
9
State
10
Forms
Adding Forms in React
You add a form with React like any other element:
Example:
Add a form that allows users to enter their name:
function MyForm() {
return (
<form>
<label>Enter your name:
<input type="text" />
</label>
</form>
)
}
togglePopup() {
this.setState({
showPopup: !this.state.showPopup
}); }
render() {
return (
13
App.js contd.
<div>
<h1> Simple Popup Example </h1>
<button onClick={this.togglePopup.bind(this)}> Click To Open</button>
{ this.state.showPopup ?
<Popup text='X' closePopup={this.togglePopup.bind(this)} />
: null
}
</div>
);
}
}
export default App;
14
How to create Dialog Box using Material UI in ReactJS?
Dialogs inform users about a task and can contain critical information, require decisions, or
involve multiple tasks.
Material UI for React has this component available for us and it is very easy to integrate. We can
create the dialog box in ReactJS using the following approach:
After creating the ReactJS application, Install the material-ui modules using the following
command:
Ref:https://www.geeksforgeeks.org/how-to-create-dialog-box-in-reactjs/
15
Simple table const data = [
{ name: "Anom", gender: "Male" },
{ name: "Megha", gender: "Female" },
]
function App() {
return ( <div className="App">
<table>
<tr>
<th>Name</th>
<th>Gender</th>
</tr>
{data.map((val, key) => {
return (
<tr key={key}>
<td>{val.name}</td>
<td>{val.gender}</td>
</tr>
)
})}
</table>
</div>
);}
16
Grid
The grid system is implemented with the Grid component:
17
Grid
<Grid container spacing={2}>
<Grid item xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid item xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid item xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid item xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
Ref:https://mui.com/components/grid/
18
Simple To-do App using reactjs
LINK : https://towardsdatascience.com/build-a-simple-todo-app-using-react-a492adc9c8a4
19
Q&A
Thank you!