React Js – Open source JavaScript library

What is react js? React java scipt

React Js – Open source JavaScript library

React Js is an open source JavaScript library for building user interfaces created by Facebook. They say it right up front here and to me, this is the best description of it now, people like to maybe claim it’s a Framework but at the end of the day you just really need to think about this.

What is React Js?

What is React Js

You’re building a website and you need something to be interactive or potentially a dynamic interface right and it doesn’t necessarily have to be crazy interactive. It could just be a general interface, I mean they make static site generators out of react Js now.

So, either way, the whole point of react Js is just for building interfaces whether that’s interfaces that you click on something and something else changes and data loads. But at the end of the day, you’re just building interfaces and you can drop in if you want it to the right you could have a module of your site that is reactJs.

And they may be reactJs is just rendering a very small portion of your website it could be an entire HTML website and using react Js. You could drop in an interface maybe if this interface needs to be dynamic or something like that. So usually I think the misconceptions about react are that it does more than you think it.

People might think that it’s a whole framework it has all this sort of stuff in it. In reality, react is just code that makes it dead simple to interact with elements and build dynamic components and buy components.

I just mean areas or things in your website right a good way to think about it would be to even just look on this page overall like what could be a component here. Well this search area up top here search docks, this could be a component.

So if you think about it, this particular user interface requires that when you click on it and you start typing that a list of search terms just start coming up and then allows you to select one and then go on to something else but this thing’s a sort of doesn’t happen with basic HTML right and you couldn’t necessarily do all of this in the same way server-side or something

like that this requires that when the user in the browser starts typing something some dynamic stuff happens and some interfaces change or load or something like that and so that’s really the purpose of react right it’s to build cool stuff like this stuff that is dynamic now.

JSX and HTML

What is React Js

Let’s talk a little bit about what react looks like and if we kind of scroll down here we can see some examples and you may confuse code that looks like this with well react itself and that’s a major turnoff for some people is the use of HTML in JavaScript and the hits it’s not necessarily HTML it’s a language called JSX which by the way is optional you don’t even have to use jazz if we

were to uncheck this checkbox you could see that this is what react looks like without JSX now honestly it’s recommended to use JSX . I personally do it’s a nice way to work in it but it

shouldn’t turn you off because honestly one of the benefits of using JSX is that you’re able to interact with the Dom in the way that you know how right the way that’s very familiar you’ve been writing HTML for all of these years. We can write HTML in a way that’s 100% connected to JavaScript and it’s really connected in a nice way that you can interact in them and have encapsulation and all sorts of really great stuff that you can’t have with HTML not only that but it provides some sort of structure where a component sort of encapsulates everything that a component would do instead of writing a bunch of jQuery right because when you’re writing a jQuery you have your code that’s interacting with the HTML but at the

end of the day those two things are entirely separate and they’re interacting with each other here this whole thing is encapsulated in one little thing  and just makes working with it just one-to-one SuperDuper easy in addition components also have something called state where well you can change their state.

 

About State in ReactJS

What is React Js

What is a state in Reactjs? You can think of it as a toggle. Toggle has two states on or off right and with reactjs, you can set that into the component this on or off value and you can trigger it, change it, whatever and then do something with that value further. It’s nothing groundbreaking in that regard but the fact that this state lives within this component and again a nice way to encapsulate everything. Now lastly we have some really cool stuff the fact that you’re building components.

 

Explaining State with Analogy

I like to describe these I don’t know if this is a great metaphor analogy you know but as Lego blocks right you have these blocks that you’re creating with your components. You can connect them together to make things. The reason why this doesn’t hold up entirely is

because react has this parent-child relationship obviously that Lego blocks don’t but what’s cool about this is that you can grab these different components from elsewhere from NPM someone else has written. You can use it in your project. They can be these macro things that generate full-on tables and charts.

It can be very micro like a simple toggle component that simply just makes it so you don’t have to write those state changes all the time. This kind of things that allow react to be so flexible. It’s one of the reasons why it’s really had just an absolutely blown up in the community now another great feature of react itself is that you can use react code on the client or server or both.

If we were to look at the code where you could see everything server-side rendered as well right this code is coming straight out of the HTML that’s loaded in this page but here’s the kicker. I wrote the same code client-side and server-side that means I didn’t have to write let’s say if you’re talking about WordPress. I didn’t have to write a WordPress theme and then write a WordPress theme in PHP. Then write some JavaScript to interact with it in the Dom those are all together in one so these are just some of the things about reacting reasons why people like it for the most part. It’s a fairly small library for working with user interfaces and it’s extremely capable one of the cool things that reactjs did.

 

When it came out as well instead of trying to do everything. It tried to do just one thing really well and because of that, the community is extremely flexible. If you want to use other things in coordination with reactjs it’s extremely easy reactjs is not trying to do everything it’s not trying to. It’s just basically handling your user interface and how it’s displayed and updated on the screen so I’ve gone this far without talking about the virtual DOM which is one of the features that one of the things that people really really like about how react performs and essentially what the

What is virtual Dom (Document Object Model)

It’s if you well the Dom which is the document object model is essentially what the browser sees as HTML as a structure of your website and it’s how you interact with your website in the browser.

What react does is it basically creates an in-memory data structure cache so it’s caching what it looks. Then it’s computing differences and then it’s only changing what needs to be changed right now one thing that’s great about that is you get some really really fast page updates.

React js virtual dom

When you change things and move things around the only thing that needs to be changed is changed and everything else stays put and therefore react can be extremely fast again I mentioned this parent-child relationship as well basically where data comes down from one component into the next and it greatly mimics how you generally think of HTML structure overall.

ReactJs virtual Dom

If you look at some of my code right here you can see we have something like a toggle that wraps around a user menu wrapper that wraps around a user menu icon that wraps around a Gravatar now what’s interesting about this whole flow is that data can come down where I have the user passed into this component.

I can then use this same user and a child component whether it’s in the same file or not pass through something called props now if you want to learn about all this stuff again check out the react course but for the most part you always have this sort of top-down data structure where stuff’s going in from parent to child It makes knowing what’s going we’re extremely easy now another thing that came about with react is react native allowing you to write it basically reacts code you can write essentially code that looks just like this the only difference is you’re using custom components built by

Facebook that interacts with native API’s to build really like native applications not as a wrapper around an HTML site put into an app. But a real application and that is something that’s extremely powerful. Really you couldn’t do before right you locations with JavaScript you just couldn’t so again all of this stuff you hear the words JSX.

You hear virtual Dom you hear state you hear things like Redux which actually isn’t part of react itself you hear all of these things and think gosh react seems complex. I don’t want to write HTML inside of JavaScript but at the end of the day like I mentioned that react is simply just a way to write user interfaces you can use it as much or as little as you want. You don’t need to build your entire app and react however as I said before because react can be server-side rendered building your entire site. Reactjs is not a terrible idea, in fact, I think it, in fact, there’s a reason why it’s really absolutely

blown up. Another great thing about reactjs is that it teaches you some actual legit JavaScript skills that you don’t get from other frameworks. One thing I really like about reactjs is that things

are just based on JavaScript, for instance, we have a component which is essentially just a class right instead of being something far out of JavaScript world. We’re defining a new class and all

it’s doing is an extending an existing class in that class comes from reactjs that’s what gives us components some of its powers right. Even though there is some jargony stuff here we still have a constructor we have we have methods in here. We’re using just straight-up

JavaScript for instance.

It doesn’t try to do looping or anything like that for you. There’s no ng for loops and stuff built-in to react you actually use legit array functions from JavaScript and you see things like a map that filter and reduce being used and those things can be scary for javascript developers or even web developers. All right if you haven’t

used that stuff it looks scary error functions all the stuff looks scary but the great thing is that

these are skills that you take with you outside of react they do not react specific skills this is straight-up JavaScript skills so another reason I really love working in react now let’s talk about something else you can take with you.

You can take your JSX and react code with you as well there’s a lot of other libraries that interface with Reax API, for instance, we have pre-act which is a three kilobyte alternative to react with the same as with the same es2015 API so what’s cool about pre-act is that this library aims to be able to be not

necessarily a drop-in replacement but a replacement for react nonetheless that’s not going to make you feel locked into a facebook project but more or less luck but more or less feel right at home building your components and another one is inferno which is a super-fast library

Jordan Wolk an engineer on Facebook was influenced by angular and some other stuff

What is React Js

Although I don’t know what the current speed comparisons to the latest version of react as they do say it’s five times faster than reactjs. But honestly, I’m not sure if this has to do with the latest version of react witches a notable improvement on performance. Some quick things about the history of our reactjs just so you know a little bit here it was created by Jordan Wolk an engineer on facebook. He was influenced by angular and some other stuff and created react where it was first used in Facebook’s feed in 2011 and so it had been around for a little bit before it was open sourced in 2013 and when it was open sourced in 2013. When it started to catch on then in a 2015 react native came out and that sort of blew the doors off again sort of blowing people’s minds that the ability to create native apps in JavaScript and most recently in 2017 react released.

 

Their latest version 16 which is also known as react fiber basically it’s an entirely new core algorithm that makes his thing run super fast. Going to be the foundation for a whole bunch of future improvements and things that fix some of the things that fix some of the issues that we’ll have with maybe some of the way.

We write react components so that’s pretty much it if there’s one thing you can take away from this is that react is not this big scary beast it’s not this giant foreign alien it’s not something that’s going to destroy the way you write HTML or understand websites but it will completely blow your mind in terms of how easy it is to build excellent user interfaces.

One of the reasons why it’s so popular although it is polarizing when people see things like HTML and JavaScript. As well as the general look of react Akande it can definitely put some people off but for those people, because I was certainly one of them you know I was initially put off, by the way, react looked. Felt I would recommend that you plow through that and learn it because honestly, nothing has made me a better developer than learning react and I feel like I can say that confidently so check it out react org if you want to learn more about reactjs.


Leave a Reply