Docsity

React Exercises: Installing create-react-app, JSX, Components, Lists, Error Handling, Assignments of Computer science

Toggle sidebar
bg1
Name:Sudarshan Dilip Gundale
Std:SYIT Roll:392
Practical 1
Aim: Install create-react-app and create a new react project
Theory:
What is React ?
ReactJS is JavaScript library used for building reusable UI components.
According to React official documentation, following is the definition −
React is a library for building composable user interfaces. It encourages the
creation of reusable UI components, which present data that changes over time.
Lots of people use React as the V in MVC. React abstracts away the DOM
from you, offering a simpler programming model and better performance.
React can also render on the server using Node, and it can power native apps
using React Native. React implements one-way reactive data flow, which
reduces the boilerplate and is easier to reason about than traditional data
binding.
React is a JavaScript library created for building fast and interactive user
interfaces for web and mobile applications. It is an open-source, component-
based, front-end library responsible only for the application’s view layer. In
Model View Controller (MVC) architecture, the view layer is responsible for
how the app looks and feels. React was created by Jordan Walke, a software
engineer at Facebook. Let’s take a look at an Instagram webpage example,
entirely built using React, to get a better understanding of how React works. As
the illustration shows, React divides the UI into multiple components, which
makes the code easier to debug. This way, each component has its property and
function.
Requirements :
Node.js with npm in path
Steps:
1. Open command prompt
2. Create a folder for your React Project by running md <folder_name>
3. Navigate to the folder by running cd <folder_name>
1 | P a g e
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download React Exercises: Installing create-react-app, JSX, Components, Lists, Error Handling and more Assignments Computer science in PDF only on Docsity!

Name:Sudarshan Dilip Gundale Std:SYIT Roll:

Practical 1

Aim: Install create-react-app and create a new react project

Theory:

What is React?

ReactJS is JavaScript library used for building reusable UI components. According to React official documentation, following is the definition − React is a library for building composable user interfaces. It encourages the creation of reusable UI components, which present data that changes over time. Lots of people use React as the V in MVC. React abstracts away the DOM from you, offering a simpler programming model and better performance. React can also render on the server using Node, and it can power native apps using React Native. React implements one-way reactive data flow, which reduces the boilerplate and is easier to reason about than traditional data binding. React is a JavaScript library created for building fast and interactive user interfaces for web and mobile applications. It is an open-source, component- based, front-end library responsible only for the application’s view layer. In Model View Controller (MVC) architecture, the view layer is responsible for how the app looks and feels. React was created by Jordan Walke, a software engineer at Facebook. Let’s take a look at an Instagram webpage example, entirely built using React, to get a better understanding of how React works. As the illustration shows, React divides the UI into multiple components, which makes the code easier to debug. This way, each component has its property and function.

Requirements :

Node.js with npm in path Steps:

1. Open command prompt 2. Create a folder for your React Project by running md <folder_name> 3. Navigate to the folder by running cd <folder_name>

4. To create an react app run npm install –g create-react-app 5. Navigate to the folder by running cd <app_name> 6. Then to start running the react web page on the server type npm start 7. To access the web page, go on http://localhost:

Practical 2

Aim: Create JSX expressions with different Javascript expression, apply Css via className and Styles, use Conditionals.

Theory:

It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript.JSX produces React “elements”. We will explore rendering them to the DOM in the next section. Below, you can find the basics of JSX necessary to get you started.React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time, and how the data is prepared for display.Instead of artificially separating technologies by putting markup and logic in separate files, React separates concerns with loosely coupled units called “components” that contain both. We will come back to components in a further section, but if you’re not yet comfortable putting markup in JS, this talk might convince you otherwise.React doesn’t require using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages. JSX is a technology that was introduced by React.Although React can work completely fine without using JSX, it’s an ideal technology to work with components, so React benefits a lot from JSX.At first, you might think that using JSX is like mixing HTML and JavaScript (and as you’ll see CSS).But this is not true, because what you are really doing when using JSX syntax is writing a declarative syntax of what a component UI should be.And you’re describing that UI not using strings, but instead using JavaScript, which allows you to do many nice things.

Code 1:

Code 2:

Practical 3

Aim: Create a stateful component and stateless component. Pass data from parent component to child component using props. Implement child to parent communication using callbacks.

Theory:

Stateful and Stateless Components Today, we’re going to review what stateful and stateless components are in React, how you can tell the difference, and the complex process of deciding whether to make components stateful or not. Understanding Stateful components: A Stateful component has a state and a life-cycle. A component's state is very similar to a locally declared variable in a javascript function. The state containing the properties of the component can only be modified inside of the component. The content of the state is changed by the components event handlers to trigger updates to the user interface. When the state's content changes the component re-renders. A life-cycle is a method that is called when a mount, update, unmount, or error handling phase occurs on the component. Keep in mind the minimal representation of a components state and utilize the render to return for any additional info. This will help to avoid repeating code. Avoid creating stateful components to avoid unnecessary complexity when it is possible. Understanding Stateless Components: Unlike a component's state, props give components the ability to receive data from a parent component when the content inside the component needs to be changed. Most components will receive props and render a React element. Props are used to configure the values passed into the component. Props should not change once they are set. Think of them as a javascript functions arguments that on invocation are sent into a function but in this case they are sent to component as attributes.

Code1:

Code 2:

Output 2:

Code:

Output: