Learn ReactJS in Only 6 Minutes

Learn ReactJS in Only 6 Minutes

Configuration

When getting started with React, the simplest way is: an HTML file which imports the React and the ReactDOM libraries using script tags, like this:

<html>
<head>
<script src="https://unpkg.com/react@15/dist/react.min.js"> </script><script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js">
</script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">

/*
ADD REACT CODE HERE
*/

</script>
</body>
</html>

We’ve likewise imported Babel, as React utilizes something many refer to as JSX to compose markup. We’ll have to change this JSX into plain JavaScript, with the goal that the program can comprehend it.

There are more two things I want you to notice:
The <div> with the id of #root. This is the entry point for our app. This is where our entire app will live.
The <script type=”text/babel”> tag in the body. This is where we’ll write our React.js code.

Components

Everything in React is a segment, and these typically appear as JavaScript classes. You make a part by reaching out upon the React-Component class. We should make a part called Hello.

class Hello extends React.Component {
render() {
return <h1>Hello world!</h1>;
}
}

You at that point characterize the techniques for the segment. In our precedent, we just have one strategy, and it’s called render().

Inside render() you’ll restore a portrayal of what you need React to draw on the page. For the situation above, we essentially need it to show a h1 tag with the content Hello world! inside it.

To inspire our modest application to render on the screen we likewise need to utilize ReactDOM.render():

ReactDOM.render(
<Hello />,
document.getElementById("root")
);

So this is the place we interface our Hello part with the section point for the application (<div id=”root”></div>). It results in the accompanying:

The HTML’s grammar we just took a gander at (<h1> and <Hello/>) is the JSX code I referenced before. It’s not really HTML, however what you compose there ends up as HTML labels in the DOM.

The subsequent stage is to get our application to deal with information.

Handling data

There are two sorts of information in React: props and state. The contrast between the two is somewhat precarious to comprehend to start with don’t as well, stress on the off chance that you discover it somewhat befuddling. It’ll wind up simpler once you begin working with them.

The key distinction is that state is private and can be changed from inside the part itself. Props are outside, and not controlled by the segment itself. It’s passed down from parts higher up the progression, who additionally control the information.

A segment can change its inward state straightforwardly. It can not change its props specifically.

Let’s take a closer look at props first.

Props

Our Hello segment is extremely static, and it renders out a similar message in any case. A major piece of React is reusability, which means the capacity to compose a segment once, and afterward reuse it in various use cases — for model, to show distinctive messages.

To accomplish this sort of reusability, we’ll include props. This is the manner by which you pass props to a part (featured in strong):

ReactDOM.render(
<Hello message="my friend" />,
document.getElementById("root")
);

This prop is called message and has the esteem “my companion“. We can get to this prop inside the Hello part by referencing this.props.message, similar to this:

class Hello extends React.Component {
render() {
return <h1>Hello {this.props.message}!</h1>;
}
}

As a result, this is rendered on the screen:

The reason we’re composing {this.props.message} with wavy props is on the grounds that we have to advise the JSX that we need to include a JavaScript articulation. This is called escaping.

So now we have a reusable segment which can render whatever message we need on the page. Wow!

Notwithstanding, consider the possibility that we need the segment to have the capacity to change its very own information. At that point we need to utilize state!

State

The other method for putting away information in React is in the segment’s state. What’s more, dissimilar to props — which can’t be changed straightforwardly by the component — the state can.

So in the event that you need the information in your application to change — for model dependent on client interactions — it must be put away in a segment’s state some place in the application.

Initializing state

To instate the state, essentially set this.state in the constructor() technique for the class. Our state is an article which for our situation just has one key called message.

class Hello extends React.Component {

constructor(){
super();
this.state = {
message: "my friend (from state)!"
};
}

render() {
return <h1>Hello {this.state.message}!</h1>;
}
}

Before we set the state, we need to call super() in the constructor. This is on the grounds that this is uninitialized before super() has been called.

Changing the State

To adjust the state, just call this.setState(), going in the new state object as the contention. We’ll do this inside a technique which we’ll call updateMessage.

class Hello extends React.Component {

constructor(){
super();
this.state = {
message: "my friend (from state)!"
};
this.updateMessage = this.updateMessage.bind(this);
}
updateMessage() {
this.setState({
message: "my friend (from changed state)!"
});
}
render() {
return <h1>Hello {this.state.message}!</h1>;
}
}

Note: To make this work, we likewise needed to tie the this watchword to the updateMessage technique. Else we couldn’t have gotten to this in the strategy.

The subsequent stage is to make a catch to tap on, with the goal that we can trigger the updateMessage() technique.

So how about we add a catch to the render() technique:

render() {
return (
<div>
<h1>Hello {this.state.message}!</h1>
<button onClick={this.updateMessage}>Click me!</button>
</div>
)
}

Here, we’re snaring an occasion audience onto the catch, tuning in for the onClick occasion. At the point when this is activated, we call the updateMessage technique.

Here’s the whole segment:

class Hello extends React.Component {

constructor(){
super();
this.state = {
message: "my friend (from state)!"
};
this.updateMessage = this.updateMessage.bind(this);
}
updateMessage() {
this.setState({
message: "my friend (from changed state)!"
});
}
render() {
return (
<div>
<h1>Hello {this.state.message}!</h1>
<button onClick={this.updateMessage}>Click me!</button>
</div>
)
}
}

The updateMessage strategy at that point calls this.setState() which changes the this.state.message esteem. What’s more, when we tap the catch, here’s the means by which that will play out:

class Hello extends React.Component {

constructor(){
super();
this.state = {
message: "my friend (from state)!"
};
this.updateMessage = this.updateMessage.bind(this);
}
updateMessage() {
this.setState({
message: "my friend (from changed state)!"
});
}
render() {
return (
<div>
<h1>Hello {this.state.message}!</h1>
<button onClick={this.updateMessage}>Click me!</button>
</div>
)
}
}

Well done! You currently have an extremely essential comprehension of the most vital ideas in React.

Thanks for the read! :)
Best way to set goal with your full satisfaction

Best way to set goal with your full satisfaction

Well, it is natural that everyone wants to achieve everything, but i’ll not say it is not possible, everything is possible, But its fact that it’s very hard to make it possible. You wanna may be a doctor, engineer, programmer or designer etc. Yes! you can be, But you can’t be everything at the same time. You can be an only perfect doctor or only perfect engineer at the same time. If you wanna be both then it’s fact that there will be no perfection, Dear reader! don’t do excessive every-time neither think access. You will be messed up with bunch of goals, thoughts and even unable to set a goal and make yourself specific and niether satisfaction and happiness in your life.

You must have to know that what i’ve experienced in my life, You know I believe it’s so simple to set a goal. The big question is how?

Well! Again i am saying , it is so simple. But the question is How? because this is not the actual answer Hahahh!, Don’t be serious while reading this. I’ll need your smile here to go through.

Alright! No Fun, Let’s be serious and be focus while reading ahead, I am telling you the simple and smart way! One thing keep in your memory before getting to know the smart way, you don’t think that career is your whole life. As i told you before, that you can’t be everything at the same time. You have to specified yourself in a particular field. Choose a best field, Ride and trip to journey to achieve the goal. But the question is, How to set a goal and How to be specific??

Well, Dears and nears, I am asking you one thing? what is doctor, engineer, programmer or designer etc, its your max 6-8 hours of your whole day and what about the remaining hours of the day, everything believes those remaining hours are your actual life and precious hours of your life. Feel it that’s why it seems complex for you, Coz you have set as full time and no time for mind refresh and other activities and precious moments of your life. Don’t miss the precious moments of your life, gone time never comes back. When any question arises we human every time go through complex way then turns into simple way and solve!

Just Think! You are going to spend only 6 to 8 hours to your job. So, it’s so simple! Don’t take it complex, try it easy. What if you unable to achieve your goal, what if you unable to be a doctor, engineer…. that you dreamed. You have the remaining beautiful hours, the precious time that which is your whole life! your family, your child, your home, you social life, your friends, your exercise… Be satisfied from your life, either your are failed or succeed.

Jack MA well said to his son that: “Son you don’t need to be in the top three in your class, being in the middle is fine, so long as your grades aren’t too bad. Only this kind of person has enough free time to learn other skills”.

Most of us lose the race and challenges, when they failed to achieve their goal on first attempt. Don’t forget 99% of successful people become successful after having go through failures and hurdles many time again and again.

That’s it, failure is just a hint to move ahead more precisely to go through towards your goal.
I’ll try to explain the failure in short story!

I remember very well when i was 7 year and first time admitted to school, a teacher gave me a paper which contains some alphabets in the form of dots format, i have marked those alphabets very precisely and with perfection which consists of large quantity of dots near to each other. While those alphabets which are in format of less quantity of dots and those dots are far from each other, I marked but not precisely and neither perfection with dozens of confusions, why because it much effort and more experience. So where is the perfection, OffCourse, in which large quantity of dots that are near to each other.

Those dots are, likely to failures in your life, On each dot you look forward and backward to take further step for better and perfection, Right! , as how much you are failed as it as you’re be able to achieve the perfection to achieve your goal with more power and experience. Because next time you’re not gonna through previous step, because you have already experienced with it, that was failure step. It is very important that you should give positive reward to yourself, well, I am failed and I shouldn’t stop here, because i have experienced and got hint to go ahead and I am near to my goal.

Remember! A person who achieves his/her goal lucky on first attempt have didn’t much experience as compare to the person who stuck in problems, failed failed failed…. Then achieved goal. Because he/she suffered from failures and he/she is much more strong and powerful. As like the dots, he or she can easily and precisely predicts the next step. Then step, step, step … and finally! congratulations for achieving the goal.

At last few words, don’t forget never ever.

 Today is cruel. Tomorrow is crueler. And the day after tomorrow is beautiful

Jack MA

Please comment below and share us your suggestions. Share my words to your friends.
Thank you!

An Introduction to Javascript 2018

An Introduction to Javascript 2018

What is Javascript ?

JavaScript was initially created to “make webpages alive”.

The programs in this language are called scripts. They can be written right in the HTML and execute automatically as the page loads.

Scripts are provided and executed as a plain text. They don’t need a special preparation or a compilation to run.In this aspect, JavaScript is very different from another language called Java

Why Javascript is ?

When JavaScript was created, it initially had another name: “LiveScript”. But Java language was very popular at that time, so it was decided that positioning a new language as a “younger brother” of Java would help.

But as it evolved, JavaScript became a fully independent language, with its own specification called ECMAScript, and now it has no relation to Java at all.

At present, JavaScript can execute not only in the browser, but also on the server, or actually on any device where there exists a special program called the JavaScript engine.

The browser has an embedded engine, sometimes it’s also called a “JavaScript virtual machine”.

Different engines have different “codenames”, for example:

  • V8 – in Chrome and Opera.
  • SpiderMonkey – in Firefox.

…There are other codenames like “Trident”, “Chakra” for different versions of IE, “ChakraCore” for Microsoft Edge, “Nitro” and “SquirrelFish” for Safari etc.
The terms above are good to remember, because they are used in developer articles on the internet. We’ll use them too. For instance, if “a feature X is supported by V8”, then it probably works in Chrome and Opera.

How engines work?

Engines are complicated. But the basics are easy.

  1. The engine (embedded if it’s a browser) reads (“parses”) the script.
  2. Then it converts (“compiles”) the script to the machine language.
  3. And then the machine code runs, pretty fast.

The engine applies optimizations on every stage of the process. It even watches the compiled script as it runs, analyzes the data that flows through it and applies optimizations to the machine code based on that knowledge. At the end, scripts are quite fast.

What can in-browser JavaScript do?

The modern JavaScript is a “safe” programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it.

The capabilities greatly depend on the environment that runs JavaScript. For instance, Node.JS supports functions that allow JavaScript to read/write arbitrary files, perform network requests etc.

In-browser JavaScript can do everything related to webpage manipulation, interaction with the user and the webserver.

For instance, in-browser JavaScript is able to:

  • Add new HTML to the page, change the existing content, modify styles.
  • React to user actions, run on mouse clicks, pointer movements, key presses.
  • Send requests over the network to remote servers, download and upload files (so-called AJAX and COMET technologies).
  • Get and set cookies, ask questions to the visitor, show messages.
  • Remember the data on the client-side (“local storage”).

What can’t in-browser JavaScript do?

JavaScript’s abilities in the browser are limited for the sake of the user’s safety. The aim is to prevent an evil webpage from accessing private information or harming the user’s data.

The examples of such restrictions are:

  • JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS system functions.Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like “dropping” a file into a browser window or selecting it via an <input> tag.There are ways to interact with camera/microphone and other devices, but they require a user’s explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the NSA.
  • Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites (from a different domain, protocol or port).This is called the “Same Origin Policy”. To work around that, both pages must contain a special JavaScript code that handles data exchange.The limitation is again for user’s safety. A page from http://anysite.com which a user has opened must not be able to access another browser tab with the URL http://gmail.com and steal information from there.
  • JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that’s safety limitations.

 

Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow installing plugin/extensions which may get extended permissions.

What makes JavaScript unique?

There are at least three great things about JavaScript:

  • Full integration with HTML/CSS.
  • Simple things done simply.
  • Supported by all major browsers and enabled by default.

Combined, these three things exist only in JavaScript and no other browser technology.

That’s w