• Code

    Watch the bar turn green with TDD

    When there are bugs, there is probably nothing more pleasing than figure out a way to: Write a failing unit test that reproduces that bug. Fix it and watch the bar turn green again, forever and ever 😉 If your goal is to stay green for all of your existing tests by using the Test Driven Development (TDD) approach, you need to mentally train yourself to: Think about the behavior around the next pieces of functionalities that you need in your code, then start moving towards your end goal in tiny steps and you will end up seeing tangible progress every moment. Write unit test first, they shouldn’t be written…

    Comentarios desactivados en Watch the bar turn green with TDD
  • Code

    Use SWR with React Suspense

    This article will explore how you should use the awesome useSWR hook for remote data fetching. Why the SWR hooks for remote data fetching? Because SWR (stale-while-revalidate) is a fully dedicated React Hooks library for remote data fetching. So basically, this is what SWR does: First returns the data from cache (stale) Then sends the fetch request (revalidate). Finally comes with the up-to-date data again. Why Suspense? Because Suspense will definitely help you to maintain a consistent UI in the face of asynchronous dependencies. Something I prefer to call on-demand loaded React components. All you need is to: Set the suspense: true as one of the useSWR hook options. Wrap…

    Comentarios desactivados en Use SWR with React Suspense
  • Code

    Manage non connected components state

    It is pretty simple, the React Context API helps to simplify the way you pass or share data across components. Let’s start with using createContext() to offer a custom Provider component, including its Consumer component for interacting with your custom global state later: Great thing about the Provider is that it is really useful to make the state available to all your child components: The Consumer component goal is simple, it just consume the data that comes from the Provider, without any need for prop drilling your components. Just combine the Context API with the useReducer Hook to start enjoying the features of a custom and very simple global state…

    Comentarios desactivados en Manage non connected components state
  • Code

    Control your load prioritization in React

    Let’s start talking about the idea behind bundle splitting in React , it is pretty simple as handling multiple bundles that can be dynamically loaded on demand at runtime. Basically, you should start: Importing all your dynamic imports as regular components with React.lazy Rendering all your lazy components inside a Suspense component. The outcome is pretty awesome too. You will end up with smaller bundles thanks to this control resource load prioritization approach, which generally give you a major impact on your React App load time. Complete code src/routes/Routes.js src/components/States/States.js

    Comentarios desactivados en Control your load prioritization in React