LM-6-Basics of React
LM-6-Basics of React
JavaScript).
programming concepts.
Native Web App, Benefits of Native App, Scenarios to create Native App, Tools for creating
Native App, Cons of Native App, Popular Native App Development Frameworks, Java &
Kotlin for Android, Swift & Objective-C for iOS, Basics of React Native, Native
1.JavaScript and React: React Native apps are built using JavaScript, a widely
used programming language for web development. React Native uses the React
library, which allows developers to create reusable user interface components.
React follows a declarative approach, where developers define how the app should
look and behave based on the state of the application.
CCS332/AD/III CSE/VI SEM/KG-KiTE
Basics of React Native
3.Cross-Platform: One of the key advantages of React Native is its ability to develop
cross platform apps. This means you can write a single codebase and deploy it on both
iOS and Android platforms, reducing development time and effort.
5.Hot Reloading: React Native supports hot reloading, allowing developers to see
the changes they make in the code immediately reflected in the running app,
without the need to recompile the entire project. This makes the development
process faster and more efficient.
CCS332/AD/III CSE/VI SEM/KG-KiTE
Basics of React Native
6.Styling: React Native uses a style system similar to CSS for styling
components. Developers can use Flexbox layout to create responsive and
flexible UIs that adapt to different screen sizes and orientations.
Overall, React Native is a powerful tool for building cross-platform mobile apps,
especially for projects that prioritize code reusability and quick development
cycles. Its strong community support and active development make it an attractive
choice for many developers and businesses.
CCS332/AD/III CSE/VI SEM/KG-KiTE
Native Components
Native components in the context of React Native refer to UI elements that are
rendered using native platform-specific views. These components allow
developers to build user interfaces that look and feel like native apps on iOS
and Android. React Native bridges JavaScript code with the native platform's
components to provide a seamless and performant user experience.
6. Button: The <Button> component is used for creating buttons that trigger
actions
The key advantage of using native components is that they provide a more authentic
native look and feel, as they leverage the native platform's UI elements. React Native
bridges the gap between JavaScript and the native platform, ensuring that the app's UI
components are rendered natively, resulting in better performance and user experience.
By using these native components, React Native developers can build apps that are
visually consistent with native apps on both iOS and Android, making the
development process efficient and enabling code reuse across different platforms
JSX (JavaScript XML) is a syntax extension for JavaScript that allows developers to
write HTML-like code within JavaScript. It is commonly used with libraries and
frameworks like React and React Native to define the structure of user interfaces. JSX
provides a more concise and readable way to create UI components compared to
manually manipulating the DOM in JavaScript.
In JSX, you can write HTML-like elements directly in your JavaScript code.
For example:
In the above example, We are defining a JSX element with a tag containing the text "Hello, JSX!". This JSX
code will be transformed into equivalent JavaScript code by a transpiler (like Babel) before it's executed in the
browser or on a mobile device.
JSX elements can also include attributes and support JavaScript expressions within curly braces . For instance:
In this example, the name variable is used within the JSX expression to display dynamic content. JSX makes it
easier for developers to express the UI components in a more declarative manner, similar to how they would
describe the desired UI structure in HTML. Under the hood, JSX gets transpiled to JavaScript function calls
that create React elements, which are then rendered to the DOM or native components by React or React
Native respectively.
JSX is not mandatory when using React or React Native, but it's widely adopted due to
its readability and ease of use. Developers can write the equivalent JavaScript code
without JSX, but using JSX makes the code more expressive and easier to understand,
especially for UI-intensive applications.
In React (and React Native), states refer to the dynamic data that can change during
the lifetime of a component.
In JSX, you can use states to manage and update the content of your components,
allowing them to respond to user interactions or changes in the application's data.
To use states in a React or React Native component, you typically follow these steps:
1. Initialize State: You define the initial state of your component within its
constructor or using the useState hook (in functional components). The state is usually
defined as an object containing key-value pairs representing different data elements.
CCS332/AD/III CSE/VI SEM/KG-KiTE
JSX States
counter: 0,
When the state is updated, React will automatically re-render the component and
update parts of the JSX that depend on the changed state. This allows you to build
interactive and dynamic UI components that respond to user actions or data changes.
States are an essential concept in React and React Native development, enabling
developers to create powerful and reactive user interfaces.
JSX, "props" (short for "properties") are a way to pass data from a parent component
to a child component. They allow you to customize and configure child components by
providing them with specific values or functions. When you use JSX, you can pass
props to a component by adding attributes to the JSX element. These attributes are
then accessible within the child component as properties. Here's how you can pass
props to a child component in JSX: ParentComponent.jsx: