Advanced React Component Patterns – kentcdodds

Advanced #ReactJS Component Patterns:  by @kentcdodds #JavaScript

  • Two of my courses will be (have now been) released as part of Egghead’s annual Christmas course release celebration 🎉 One is The Beginner’s Guide to ReactJS and the other is Advanced React Component Patterns.
  • 👀The course starts with a single lesson where I implement a simple toggle component that manages its own state.
  • My hope is that by doing things this way you can quickly identify the trade-offs of the different patterns and know when each pattern would be most appropriate.The course wraps up by refactoring the toggle component to a redux component affectionately called “Rendux.” I think that you’ll be blown away…
  • This way we can easily create custom components which have access to the toggle component’s on state and the toggle helper function.There are actually six lessons dedicated to Higher Order Components in this course.
  • Hopefully with this refactor you’ll see both the power and the simplicity of the render prop pattern.The basic idea of the pattern is that rather than have the toggle component be responsible for doing anything special in the render method, we delegate that responsibility over to the user and we…

An overview of some of the patterns covered in my recently released Egghead.io course (free until Friday). NOTE: This is a cross-post from my newsletter. I publish each email two weeks after it’s…
Continue reading “Advanced React Component Patterns – kentcdodds”

The secret to being a top developer is building things! Here’s a list of fun apps to build!

  • Here’s a list of fun apps to build!You can only become a great developer by putting the effort in.
  • Keep it conflict free, use whatever you want!Project #1: Trello CloneTrello clone by Indrek Lasn — Demo LinkWhat you will learn from building a trello clone:RoutingDrag and dropCreating new objects (boards, lists, cards)Handling inputs and validationClient side path: How to use local storage, saving data to the local storage, reading data from the local…
  • What you will learn:Creating users, managing users,Interacting with a database — creating, reading, editing, deleting users.Input validation and how to work with formsProject #3: Cryptocurrency tracker (native mobile app)Github repositoryHAS to be a native app — Swift, Objective-C, React Native, Java, Kotlin allowed.
  • 😊What you will learn:How native apps work.Fetching data from an API.How native layouts work.How to work with mobile simulators.Use this API.
  • Post in comments if you find a better one.In case you’re interested in how this was built, I wrote a tutorial for it.Project #4: Setup your very own webpack config from scratchWell, technically this is not an app but it’s still extremely useful to understand how webpack works under the hood….

You can only become a great developer by putting the effort in. Imagine for a moment — You can’t become fit physically by reading a lot about fitness. You actually need to go to the gym and put the…
Continue reading “The secret to being a top developer is building things! Here’s a list of fun apps to build!”

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”

How to do end-to-end testing on React Native with Detox

  • They are being performed on matched elements.Expect verifies if a certain value is as expected to be.As we can see detox covers a lot of possible user interactions that can be automated.Make our tests more readableTo be honest, we can do much better.First let’s get rid of the duplication for matchers…
  • Automate the process and land on the moon 🚀Once we reached a certain amount of tests, we thought it could be nice to automate the process and think in terms of “continuous testing”.
  • That’s why we decided to run the end-to-end test on our build server.Every new pull request that comes in, triggers unit tests with Jest on CircleCI and now also our end-to-end tests on Bitrise (our build server).
  • This is mostly due to the Detox build scripts.AlternativesWe also considered others libraries such as:Appium which is a cross platform test library where tests can be written in many languages (node, ruby, java, … ).
  • Hence, our choice of using Detox.ConclusionIn this article we saw how to handle Detox and its API, how to automate everything with Bitrise (or any CI that can runs an IOS Simulator).

When we started writing our React-Native app at Home, testing was something we took seriously from day one. While it was easy to setup a proper unit-tests workflow with Jest and Typescript, we figure…
Continue reading “How to do end-to-end testing on React Native with Detox”

How I built a Content Management System for a React app in one day

How to Build a #ContentManagement System in just 1 day!


#JavaScript #React #Reactjs #CMS

  • DYI content management system with Firebase  ReactHow I built a Content Management System for a React app in one dayFirebase + React = Quick DIY CMSThere are two ways of handling website content:Use a CMS.Hard code in the copy/image urls in the code itself.Option number 2 quick at first, and is fine…
  • However, two big problems will surface and grow as companies scale.In fact, I have personally experienced multiple times the first of these two problems at work.Problem 1: time wasted by engineerEvery time there needs to be a content change, the product team would need to ping an engineer, and the engineer…
  • This will definitely be a problem if the company ever goes international in non-English speaking countries.SolutionThe solution to these two problems is a good content management system.Pillow, where I’m currently working, had a Hackathon last week.
  • Anyone can signup for an account with their gmail, create a project, and add data to the database.Because of the NoSQL structure, I thought it would be a great way to store website copy.
  • This is what I did to structure Pillow’s landing page copy during the Hackathon:Screenshot of json data structurePillow’s website is already built with React, and that made my job a lot easier.All I needed to do on that front is install re-base, set up some configuration, and replace the hard…

Option number 2 quick at first, and is fine for an early stage startup operating in one country. However, two big problems will surface and grow as companies scale. Every time there needs to be a…
Continue reading “How I built a Content Management System for a React app in one day”

5 simple steps to quickly start a new VR project – Hacker Noon

  • This will tell git to ignore the node_modules folder and the final bundled javascript file.Step 2: Create a file structureIn project, there will be two main components, a client and a server.
  • Since this project will use webpack to bundle the react code, add another two folders into the client folder, and name them ‘src’ and ‘dist’Step 3: Creating the ServerThis will create a Node/Express server that will serve the client whenever the url is called.Create a file inside the server folder and name it index.js.Inside terminal, type yarn install and press enter.
  • Inside the terminal type: touch webpack.config.js, then add this into the file:var path = require(‘path’);var SRC_DIR = path.join(__dirname, ‘/client/src’);var DIST_DIR = path.join(__dirname, ‘/client/dist’);module.exports = { entry: `${SRC_DIR}/index.jsx`, output: { filename: ‘bundle.js’, path: DIST_DIR }, module : { loaders : [ { test : /\.
  • Go to the terminal and type yarn build and after it’s done, type yarn start .
  • In the terminal, type:yarn add aframe aframe-react add this into index.jsx (this code is copied directly from aframe-react official repo):import React from ‘react’;import ReactDOM from ‘react-dom’;import ‘aframe’;import {Entity, Scene} from ‘aframe-react’;import ‘babel-polyfill’;import App extends React.Component { render () { return ( Scene Entity geometry={{primitive: ‘box’}} material={{color: ‘red’}} position={{x: 0, y: 0, z: -5}}/ Entity particle-system={{preset: ‘snow’}}/ Entity light={{type: ‘point’}}/ Entity gltf-model={{src: ‘virtualcity.gltf’}}/ Entity text={{value: ‘Hello, WebVR!’}}

A-Frame is a great way to get into developing VR, especially for those who come from a Javascript background. For those who dont know what A-Frame is, here is the official description taken directly…
Continue reading “5 simple steps to quickly start a new VR project – Hacker Noon”