0% found this document useful (0 votes)
2 views

ReactJS Lab Manual With Solutions

The document is a lab manual for advanced web development using React-JS, detailing 14 labs covering various topics such as setting up the environment, components, state management, hooks, event handling, forms, conditional rendering, lists, styling, routing, Redux, and asynchronous operations. Each lab provides step-by-step solutions for practical implementation. The manual serves as a comprehensive guide for learning and applying React concepts effectively.

Uploaded by

Uma Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ReactJS Lab Manual With Solutions

The document is a lab manual for advanced web development using React-JS, detailing 14 labs covering various topics such as setting up the environment, components, state management, hooks, event handling, forms, conditional rendering, lists, styling, routing, Redux, and asynchronous operations. Each lab provides step-by-step solutions for practical implementation. The manual serves as a comprehensive guide for learning and applying React concepts effectively.

Uploaded by

Uma Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Advanced Web Development using React-JS Lab Manual

Lab 1: Setting up React environment, Create React App

Solution:

1. Install Node.js

2. Use 'npx create-react-app my-app'

3. Navigate to the app directory and run 'npm start'

Lab 2: Hello World, Components, JSX

Solution:

1. Create a component using function/class

2. Use JSX to return <h1>Hello World</h1>

Lab 3: Functional vs class components, Props

Solution:

1. Functional component: function Greet(props) { return <h1>Hello {props.name}</h1>; }

2. Class component: class Greet extends React.Component { render() { return <h1>Hello

{this.props.name}</h1>; } }

Lab 4: State, Lifecycle methods

Solution:

1. Use this.state in class components

2. Use lifecycle methods like componentDidMount

Lab 5: Hooks - useState, useEffect, useContext

Solution:

1. const [count, setCount] = useState(0);


2. useEffect(() => { ... }, []);

3. Use Context.Provider and useContext

Lab 6: Event handling

Solution:

1. Use onClick, onChange etc.

2. Example: <button onClick={handleClick}>Click</button>

Lab 7: Forms: controlled components, submission, validation

Solution:

1. Use value and onChange for inputs

2. Handle form submission with onSubmit

Lab 8: Conditional rendering: if, ternary

Solution:

1. if(condition) { return <A />; } else { return <B />; }

2. condition ? <A /> : <B />

Lab 9: Lists and keys

Solution:

1. Use map to render lists

2. Add unique 'key' prop to each item

Lab 10: Importance of keys

Solution:

1. Keys help React identify which items changed

2. Avoid using index as key if items are reordered


Lab 11: Styling - CSS, CSS Modules, CSS-in-JS

Solution:

1. CSS: import './App.css';

2. CSS Modules: import styles from './App.module.css';

3. CSS-in-JS: styled-components

Lab 12: React Router - setup, routes, parameters

Solution:

1. Install react-router-dom

2. Use <BrowserRouter>, <Routes>, <Route>

3. Use useParams to access route params

Lab 13: Redux - setup, actions, reducers

Solution:

1. Install redux and react-redux

2. Define actions, reducers, and use <Provider store={store}>

Lab 14: Async/await, Promises, Fetch API

Solution:

1. Use fetch('url').then(res => res.json())

2. async function fetchData() { const res = await fetch('url'); }

You might also like