If you are into WordPress or JavaScript, or even both, you might have heard the news already. WordPress is (i.e., the core committers as well as several contributors and users are) evaluating JavaScript frameworks for adoption. This post is an interview with Wes Bos about exactly that topic.
Who Is This Wes Bos?
At the end of last year, I had a straightforward, easy-to-understand and even partly visual answer to the question who Wes Bos is.
@wesbos in a nutshell:
['š', 'š', 'š'].map(š„);
// ['š', 'š', 'š']
— Thorsten Frommen (@thorstenfrommen) November 5, 2016
Unfortunately, this isnāt up to date anymore, as there are stickers missing. And kombucha. And Syntax. And… Well, that guy just has too much free time. š
Wes Bos
Anyway, Wes Bos is a full stack web developer and designer from Hamilton, Canada. You might know him from one of his awesome, high-quality video courses, for example, ES6 for Everyone, React For Beginners, or, his latest one, Learn Node. If not, you really should check them out.
Wes is a lead instructor at HackerYou and Ladies Learning Code, and a regular conference speaker. He tweets a lot and writes in his WordPress-powered blog.
Why This Interview?
One of the goals of these WordPress JavaScript chats is to make future versions of WordPress ship with a mature JavaScript framework so anyone interested in that can just make use of it. Of course, any new JavaScript-based or -powered core features will be built using the new framework, and eventually, WordPressās JavaScript codebase will be refactored bit by bit. Right now, the only two frameworks (left) in the broader discussion are React and Vue.
Several weeks ago, Evan You, creator of Vue, stepped in and responded to a few questions and comments by either WordPress core committers or other participants in the discussions. While this sure helped clarify quite a few things, it, of course, also pushed Vue as an option.
Just to make that very clear: I do not have anything against Vue at all. I only heard good things, but I never used it myself so far. However, I thought that React, as second party in this battle, should get the same as Vue: someone knowledgeable who can provide meaningful insight into using the framework in and for WordPress.
So I asked Wes if he was interested in doing this interview. Why? Of all the JavaScript professionals, teachers and influencers I know, Wes not only knows React like the back of his hand, he also has advanced WordPress knowledge. Unlike Evan Young, however, Wes is not involved in the development of any of the systems. Therefore, Wes was the optimal candidate for such an interview. Thatās why Iām still thrilled he did this. (And anything with/about Wes Bos just sells well, of course. š )
Questions and Answers
Now, letās get to the interview then.
Before we get right into JavaScript, letās briefly talk about WordPress. When did you first use it, what did you do with it since, and when (and for what) did you use it the last time?
Wes: I first used it in pretty early days, probably WordPress 1, probably eight, ten years ago. I initially got into it, and I was a big fan of that. Back then, the big plugin that got released was this thing called Flutter. It allowed you to have custom fields, and that was huge for us. But since weāve all changed through a couple different plugins. I was big in the Pods scene for a while, now Iām into the Advanced Custom Fields scene.
When did I last use it? Probably about two weeks ago. My own site is on it, my wifeās site is on it, I have a couple client websites on it that I still maintain, couple other things… Tons and tons of different installs on WordPress.
Recent WordPress JavaScript chats as well as related discussions are mostly about React vs. Vue. Was this to be expected? Is there any framework missing?
Wes: I donāt know. I think that React and Vue are sort of the hot ones right now. I think theyāre both very good choices. Obviously, thereās other frameworks that are out there. Obviously, Angular is the big one. Marko from eBay seems to be a really nice one as well. Thereās all kinds of other frameworks that could be, but I think going for the most popular one is a great idea, just because thatās going to give people the best option in being able to create things for it.
You know React inside out, no questions asked. Do you also have any experience with Vue?
Wes: Not really. I played with it a few times here or there. From my very limited impressions, it seems really easy to get up and started, which reminds me of Angular 1 days. Itās kind of like you try it, and then: oh, this is nice.
I think React has a lot of stuff that you need to keep in your head, like binding and all these weird gotchas, whereas Vue sort of just works, which is really really nice.
When and why did you choose React? Have you ever wanted to actively turn away from it? Do you see this coming?
Wes: I was initially an Angular dev, during Angular 1 days. And then Angular announced Angular 2 like way ahead of time, and they said itās gonna be totally different. So there was this two-year period where I was kinda like, well, whatās the point of putting any time into Angular 1 if itās all going to totally change. And then Angular 2 was so far away that itās not I could just sit on my hands and wait for it.
At that time, React was becoming popular, I gave it a shot, and I really liked it. I really liked how it worked, I really liked how simple it was to build stuff, I really liked how it made me a better JavaScript developer… So, yeah. Big fan of it.
Turning away from it? No, I donāt think so. Iāve always liked it. I mean, thereās lots of things that I donāt like about it, but you sort of just learn to work with those. Thatās just part of buying into a framework.
Some people mentioned creating a WordPress-specifc JavaScript framework from scratch. What do you think about that? While something like this is doable, should it really be done?
Wes: I donāt think thatās a good idea. I think you should pick something that is already out there, and something that will be around for a while. Otherwise you have to learn yet another WordPress framework. I think that sometimes developers pigeonhole themselves into being a WordPress developer, rather than just a web developer and WordPress is a toolāthatās always been my approach to it, and WordPress is just one of the many tools that I use. So, itās better to sort of get away from thinking in terms of WordPress, and get more into thinking in terms of a web developer, where WordPress can help you. So any WordPress-specific stuffāIām not always a huge fan of. Besides from things like themes and plugins, which obviously need to be done on top of the WordPress core.
Does React fit as JavaScript framework for WordPress core? What about themes or plugins?
Wes: I think so. I think that thereās gonna be some challenges in terms of sharing data, just because, in PHP and in WordPress, itās so easy to just pull in data wherever you want. And now if youāre trying to make components that need to fit into a larger JavaScript, weāre gonna need to look at something like Redux or Apollo, which will make it really simple to just inject the WordPress data into a component at any level, and be able to call these custom functions. Otherwise itās gonna be a bit hard for people to transition from thinking in terms of WordPress over to React.
There are quite a few concerns about React being hard(er) to learn. With your React For Beginners course, you claim people can learn React in an afternoon or two. How does this fit together? Do you think React is hard to learn? What do your students say?
Wes: I think React is hard to learn because people donāt necessarily know all that much about JavaScript. And then you compound that with having to learn JSX, or having to learn a whole bunch of new ES6 stuff that you might not necessarily have used before. Then thereās the whole compile stuff… I think thereās a lot of like moving targets in React, whereas with WordPress you drop a theme in and youāre up and running. So someone moving over from WordPress to React is gonna be in for a bit of surprise, because I know that there are still quite a few WordPress developers who simply just FTP in and start live-editing a file, whereas React is like the total opposite of that.
So, I think that is hard, but once you get over that initial hurdleāyou could do that by taking my course, or doing a couple tutorialsāyou can get over that fairly quickly. And I think that itās good for you, because it overall makes you a better developer. And, of course, I think thatās why my course is doing so well, because React is a little bit hard to get up and started with, so thatās exactly why you need to put in a little bit of time, or do something like my course.
My students say that itās great. They say that it was hard to initially learn, because thereās so many moving parts, thereās so many tutorials out there, but if you can have a singular resource you can just focus in on, then that would really help.
React is licensed by Facebook, and there is this additional grant of patent rights that has been subject to the most controverse discussions. Did you ever run into any trouble because of this? Or did you ever have a bad feeling when (thinking about) using React? Should WordPress?
Wes: No. But thatās because Iām not anyone who is building products that is worried about this. A lot of people asked my this question, and I donāt really know. The answer seems to be: use Preact, which uses the exact same API, but is not licensed under Facebook. So thatās sort of an easy one to do, and thatās been tested with the whole Google Java thing where they have used the same Java API, but recreated it themselves. So, I donāt know. I really wouldnāt sweat it all that much, but Iām not a lawyer at the end of the day.
Letās assume there really was some danger involved when using React, the framework. Fortunately, there are other options out there that follow the same (or fairly similar) principles that React is built on. For example, Preact. What are your thoughts on this?
Wes: Yes, I think Preact is great. Especially from performance and licensing standpoint. I think itās really cool that React has built this standard API, and then everybody can build different frameworks using the exact same API.
Something (that should be) very important is state management, both in the WordPress admin and in the front end. Do you agree? What does React itself, but also its ecosystem offer in this regard?
Wes: Yeah, you definitely need a state manager, especially when youāre going to be getting heavy. Itās easy just to use state if itās all your application. But when you get into using third-party components, or being able to integrate into somebody elseās React, a state manager is gonna help you quite a bit in this case. And at this point, Redux seems to be a really really solid option, and Iāve recently been looking at Apollo, which uses Redux under the hood, to do this as well with GraphQL. So, definitely, that needs to be taken into account when looking at WordPress.
One thing in WordPress that is not JavaScript itself, but fairly related to it is the WordPress REST API. If WordPress was shipping with React, would plugin authors gain anything when it comes to working with the WordPress REST API?
Wes: I think that if you were building a plugin these daysāand especially if WordPress adopts either Vue or Reactāthen it would be a great idea to build it entirely on top the REST API, rather than having to deal with page refreshes and whatnot. You could build some pretty slick plugins, and I know a lot authors are already doing this.
Finally, which of the two frameworks do you think will win, and ship with future WordPress releases? Why?
Wes: I donāt know. I wish that I could predict the future, butāif you pardon the punāIām more of a React-ionary guy. I think that thereās people really taking time to consider all the ins and outs of all the different frameworks, and I rather them do that than me, who hasnāt spent a whole lot of time reading into it, just sort of slinging opinions here and there.
I think whatever they choose to go withāwhether itās React or Vueāwill be a really good choice. And I think people will be pretty happy with it over the years as it starts to develop.
Thanks a lot for your time and knowledge, Wes. Really very much appreciated.
Wes: Youāre welcome.
Takeaways
- Donāt create a WordPress-specific JavaScript framework, but pick something popular that will be around for a while.
- For something like WordPress, a dedicated state manager helps. A lot. And Redux seems to be a really solid option.
- No matter if it will be React or Vue, it will be a really good choice, and people will be pretty happy with it.
What Do You Think?
If you have anything to say about either the whole WordPress JavaScript framework discussion, or something specific in this interview, please, let me know in the comments below. Thanks so much in advance.
You are amazing bro first time i see Preact!!! Thx you so much!