WordCamp Europe 2018: Unit Testing Workshop

  • Since the first official German WordCamp in Hamburg in June 2014, Thorsten fell in love with both the WordPress community and WordCamps , in particular, where he likes to both gain and share knowledge .
  • Something that was kept a secret for far too long has just been unveiled: together with my friends and fellow WordPressers, Carl Alexander and Giuseppe Mazzapica, I will be having both the honor and the pleasure of hosting a three-hours-long workshop at WordCamp Europe 2018.
  • Well, the topic of the workshop will be unit testing, and here is what we put in the application: – – We’ve all had these “Wait, what?
  • While you might benefit from having heard one or another thing about unit testing, or software testing in general, there is absolutely no prior knowledge or experience required in order to sign up for this workshop.
  • But downloading PHP, or installing MAMP, or booting up your VM for the very first time is something that should have happened before the workshop.

I’m super excited to be hosting a workshop on unit testing at WordCamp Europe 2018. If you want to know why that is, you might want to read this post.
Continue reading “WordCamp Europe 2018: Unit Testing Workshop”

Infinite scroll techniques in React – LogRocket

Infinite scroll techniques in #reactjs – LogRocket  #javascript

  • Infinite scrolling technically requires adding a scroll event listener to the window object or a certain div.
  • Implementing from the ground upAs mentioned earlier, infinite scroll is about attaching event listeners to DOM elements while watching for when the scrollbar hits the bottom of the div.
  • Look at the render function of this Component below: – Say you want to load more li items into the ul tag each time the div with the class App gets to the end of the div, how do you tackle this problem?
  • Here is what the final component should look like: – Using an infinite scroll libraryWhile the first method showed how relatively easy it is to implement infinite scroll in React applications, you might not be so content to implement event listeners yourself.
  • Instead, there is hasMoreItems which is used to tell the Infinite scroll component to detach the event listenerAn alteration to the loadMore function, which sets the hasMoreItems state to false once the items his 200ConclusionAnd there you have it, two different methods that allow you to implement infinite scroll in…

In this tutorial, Ogundipe explains two methods of implementing infinite scroll in React
Continue reading “Infinite scroll techniques in React – LogRocket”

Infinite scroll techniques In React – LogRocket

  • This determines when the scroll has reached the bottom of the div and then performs actions accordingly.In this tutorial, I will explain two methods of implementing infinite scroll in React:The first method describes implementing everything from the ground upThe second method uses an already available infinite scroll library/componentA basic understanding…
  • The items hold the number of items available to be shown as li tags while the loading state will show when the infinite loader is fetching more items.Next, create a function that renders all items:This function loops through the number of items present and create a li tag showing the…
  • Define the ComponentWillMount method:In the method above, a scroll listener was added to the myscroll ref which references the div being targeted.
  • In your application, you probably want to make a fetch or axios call to your server and then change state.But no matter your use case, the concept remains the same.Here is what the final component should look like:Using an infinite scroll libraryWhile the first method showed how relatively easy it is…
  • Instead, there is hasMoreItems which is used to tell the Infinite scroll component to detach the event listenerAn alteration to the loadMore function, which sets the hasMoreItems state to false once the items his 200ConclusionAnd there you have it, two different methods that allow you to implement infinite scroll in…

In this tutorial, Ogundipe explains two methods of implementing infinite scroll in React
Continue reading “Infinite scroll techniques In React – LogRocket”

How to create a production build using ReactJS

How to create a #production #build using #ReactJS

  • js file – – When you use your taskrunner, being it Grunt, Webpack or something else, the development code of React JS is included in the build and you get a warning in the browser console that you are in development mode.
  • If you want to create a production build when using React JS and turn off development mode, one solution is to set the NODE_ENV environment variable to “production“.
  • This can be easily done with the taskrunner Grunt, defining a task env and calling it before other tasks, as the code below, GruntFile.js, shows – – Remember to load grunt-env plugin with the following code – – after having installed it with – – The default task is watch,…
  • You don’t need to call uglify to create a production build using React, but it can be useful to minimize and obfuscate the code.
  • The browserify task includes  the presets es2015 react to create ES2015 compliant code and transform React .

Creating a production build of javascript code which uses ReactJS using the NODE_ENV environment variable and the Grunt taskrunner
Continue reading “How to create a production build using ReactJS”

Rendering a function with React – kentcdodds

  • But there are reasons for the API as it is and that’s not what we’re going over in this newsletter…With ReactSo thinking about this in the context of React:const getHomeContent = getContent(‘pages.home’)const ui = ( a href=”/about” {getHomeContent(‘nav.about’)} /a)// that’ll get you:a href=”/about”About/aSo far so good.
  • Anyway, this will break the app:const getHomeContent = getContent(‘pages.typo’)const ui = ( a href=”/about” {getHomeContent(‘nav.about’)} /a)// 💥 error 💥Again, this is happening because getContent(‘pages.typo’) will return the string {pages.typo} (to indicate that there’s no content at that path and the developer needs to fix that problem to get the content)….
  • The issue is that you can’t invoke a string but that’s what’s happening because getHomeContent is a string, not a function.A solution and a new problemSo the change I made this week makes it so when there’s no content at a given path, instead of a string, it returns a “sorta-curried”…
  • No problem.So now this wont throw an error, but we lose rendering the path if there’s no content!const getHomeContent = getContent(‘pages.typo’)const ui = ( a href=”/about” {getHomeContent(‘nav.about’)} /a)// that’ll get you:a href=”/about”/aAnd we want to make sure that we show the missing content so it’s more obvious for developers (yes…
  • Let’s rewrite the above to make this more clear:const getHomeContent = getContent(‘pages.typo’)const aboutContent = ui = a in this example is a function because the call to getContent had a typo, so we’ll never actually find content that matches the full path.

NOTE: This is a cross-post from my newsletter. I publish each email two weeks after it’s sent. Subscribe to get more content like this earlier right in your inbox! 💌 This week I was working on an…
Continue reading “Rendering a function with React – kentcdodds”

Improving the usability of your modules – kentcdodds

Improving the usability of your modules  #reactjs

  • All you have to do is use it:import getContentForFile from ‘react-i18n’const i18n = App() { return ( div h1{i18n(‘header.title’)}/h1 /div )}So that’s how it works (again, I’m sure some of you are thinking of other libs that could do this better, but please spare me the “well actually.” I’m aware…
  • const content = JSON.parse( … more stuffexport {getContentForFile as default, init}This presents a few challenges for users of the module.
  • Turns out that react-i18n actually exposed another module react-i18n/bootstrap to customize this behavior which is great, but that doesn’t resolve the problem of stuff happening if someone were to import react-i18n first.So what I did was a wrapped all side-effects in a function I exported called init(which was similar to…
  • But it’s ok now because that’s clear const messages = JSON.parse( ) // … other other stuff}// … more stuffexport {getContentForFile as default, init}So this means that anyone using the module now must call the init function, but they’re doing that on their own terms and whenever they want it…
  • However, we’re in the process of “inner sourcing” this module (and perhaps open sourcing it eventually), so folks are going to use it who use different tools and have different use cases.So, if it’s not too much work and doesn’t add too much complexity, then try to make the solution…

NOTE: This is a cross-post from my newsletter. I publish each email two weeks after it’s sent. Subscribe to get more content like this earlier right in your inbox! 💌 This last week I worked on my…
Continue reading “Improving the usability of your modules – kentcdodds”

React.js: The Hard Parts

State Management without #Redux:  by #ReactJS

  • If a user interacts with your application or refreshes the page, then we’ll look up state at that moment and rebuild the page.
  • In dynamic apps, like ones built using React, state change has to be dealt with immediately.
  • Managing state can get complicated if each component has some state.
  • Interaction with the components, like a mouse click, trigger these functions to update state.
  • For example to implement retweets: – – When the state is updated, the props will change too and render the child components again.

I am a full-stack software developer and passionate educator. I have been building for the web for almost two decades.
Continue reading “React.js: The Hard Parts”