React Posts
Why developer choose React JSReact
Why developer choose React JSReact
There are a few reasons why developers choose ReactJS and they are :-
- JavaScript XML or JSX
- React use Virtual DOM
- ReactJs Props
- One-Way Data Binding
- Quick Rendering
- SEO Friendly
- Helpful Developer Toolset
JavaScript XML or JSX
It is a markup syntax that describes the appearance of the application's interface. It creates the same syntax as HTML and is used by developers to create feedback elements.
JSX is one of the best features of React JS as it makes it very easy for developers to write building blocks.
React use Virtual DOM
This feature helps speed up the app development process. The algorithm allows the web page to be copied into React's virtual memory.
The original DOM there is represented by a virtual DOM.
ReactJs Props
ReactJS Props allows developers to move custom development data into its specific UI components. This helps in rendering JavaScript components and improving the UI development experience.
One-Way Data Binding
Feedback uses a stream of data that is directionless, forcing developers to use the callback feature to edit components and prevent them from editing directly.
Control of data flow from a single point is achieved with a JS app architecture component called Flux. It really gives developers better control over the application and makes it more flexible and effective.
Quick Rendering
This means that a small edit made at the top level can hit the app UI hard. Thanks to the virtual DOM, it can be tested first to determine the risk level with each change before finalizing all changes.
SEO Friendly
To make any application work well, it is important that the search engine selects it; Two factors are important for applications: fast load time and rendering. If both of these boxes are ticked, your app will rank higher on Google results pages.
React's super-fast rendering feature drastically reduces page load time, enabling businesses to rank their apps on the first page of Google search.
Helpful Developer Toolset
Facebook has included many developer tools in the React JS framework for React and Chrome, and they greatly help developers find parents and child components, observe their hierarchies, and test their current status.
Through self-learning, developers will be able to use emerging technologies in real, live, projects.
So, developers choose ReactJS hope this help.
Best practices for React JS developer part-2React
Best practices for React JS developer part-2React
In the previous article, we learned 5 areas or tips on Best practices for React JS developer.
In this article, we will learn more about areas or tips
- Object Destructuring.
- When pass value in props
- Tags close it self.
- Do not use underscore in any method name.
- Use alt in img tag.
Object distracting
You can use object distracting
Not Good
return (
<>
{user.firstName}
</>
)
Good
const { firstName } = user;
return (
<>
{firstName}
</>
)
When pass value in props
When pass the data between two component that time use camelCase for prop names.
Not Good
<Home
UserName="demo"
phone_number={9898989898}
/>
Good
<Home
userName="demo"
phoneNumber={9898989898}
/>
Tags close it self
Any component in not use children so closing it self
Not Good
<Home userName="demo"></Home>
Good
<Home
userName="demo"
/>
Do not use underscore in any method name
You don't need underscores in any React method.
Not Good
const _onClickHandler = () => {
// Your code
}
Good
const onClickHandler = () => {
// Your code
}
Use alt attribute in img tag
Do use alt attribute in the img tag. and don’t use picture or image name in your alt property.
Not Good
<img src="hello.png" />
Good
<img src="hello.png" alt="This is hero image" />
Best practices for React JS developerReact
Best practices for React JS developerReact
Today we are going to see best practices for React JS developer
- Passing a boolean variables.
- Do not define a function within a render
- Naming of the components
- Use of the Ternary Operators
- Don’t Need Curly Braces in string
Passing a boolean variables
Passing boolean variables in to two components.
Not Good
return (
<Home showTitle={true}/>
);
Good
return (
<Home showTitle/>
);
Do not define a function within a render
Don’t define a function inside render.
Not Good
return (
<button onClick={() => dispatch(ACTION_TO_SEND_DATA)}>
Example
</button>
)
Good
const submitData = () => dispatch(ACTION_TO_SEND_DATA)
return (
<button onClick={submitData}>
Example
</button>
)
Naming of the components
You can use PascalCase for name of the components and camelCase for name of the instances.
Not Good
import createCard from './CreateCard';
const ReservationItem = <ReservationCard />;
Good
import CreateCard from './CreateCard';
const reservationItem = <ReservationCard />;
Use of the Ternary Operators
Developer how can use ternary operator in React js.
Not Good
const { role } = user;
if(role === 'ADMIN') {
return <AdminUser />
}else{
return <NormalUser />
}
Good
const { role } = user;
return role === 'ADMIN' ? <AdminUser /> : <NormalUser />
Don’t Need Curly Braces in string
When developer passing string props to a children component
Not Good
return(
<Navbar title={"My Special App"} />
)
Good
return(
<Navbar title="My Special App" />
)
Hope this helps for React js developer
How to setup React in LaravelLaravel
How to setup React in LaravelLaravel
In this article, I show you how to set up react application in Laravel Framework. as you know react is a very flexible frontend library and works with together any backend framework, so let start and follow the following steps. I hope you have created the laravel application.
You can watch the following video tutorial or follow this article as well,
Step 1:
Let's go to the resource directory in laravel. now let's create react application. you should watch the following tutorial if you don't know how to create react application.
Step 2:
Merge the package.json
and package-lock.json
files in the root. fire npm install && npm run dev
command in terminal for compile react application to js.
Step 3:
In this step, you need to set up a webpack.mix.js
file. put the following code in the webpack.mix.js
file.
mix.options({
postCss: [
require('autoprefixer'),
],
});
mix.setPublicPath('public');
mix.webpackConfig({
resolve: {
extensions: ['.js', '.vue'],
alias: {
'@': __dirname + 'resources'
}
},
output: {
chunkFilename: 'js/chunks/[name].js',
},
}).react();
// used to run app using reactjs
mix.js('resources/react-app/src/index.js', 'public/js/app.js').version();
mix.copy('resources/react-app/public', 'public');
NOTE: Don't forget to change the index.js path based on your application name
Step 4:
Let's add <div id="root"></div>
to your application's root blade file
Step 5:
Let's inlude <script type="text/javascript" src="{{ mix('js/app.js') }}"></script>
to your application's root blade file before end the body tag.
So, the Basic setup is done. enjoy react with laravel.