What is React JS?
- React is a powerful and flexible JavaScript library for creating user interfaces. Yes, you read that correctly; it's a javascript library, not a framework.
- React was created by Facebook in 2011 and has since grown to be one of the most popular JavaScript libraries. Facebook also maintains React.
- It breaks complex user interfaces into small, isolated pieces of code known as "components."
- React allows you to render multiple simple components to create a more complex one.
React sorts the code into components, where each component maintains all the code needed to both display and update the UI.
React is the most popular single page application builder. Single page applications are those application which loads only once and after tht every thing will be handled by JS.
Creating a development environment.
Node JS
must be installed on your PC before executing the below command in the terminal.Configure the React environment.
npx create-react-app my-app
This is the best way to start building a new single-page application in React.
This is not the only way to add
React
to your project. You can go through this link to find out more ways React Docs
Creating a basic Hello World
app
- Creating a
Hello World
component.
function HelloWorld() {
return (<h1>Hello World</h1>);
}
export default HelloWorld;
- Rendering the
Hello World
component.
import ReactDOM from 'react-dom/client';
import HelloWorld from './HelloWorld';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<HelloWorld />);
- Output
- Each component contains an odd mix of
HTML
andJavaScript
. React actually usesJSX
, a language that allowsHTML
to be mixed withJavaScript
.
JSX
allows you to use pre-definedHTML
elements as well as create your own.
I hope that my article has helped you gain a basic understanding of React.
Thanks for reading