React.js
We are introduced to React.js and learn a basic principle for combining d3 + React.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the Fullstack D3 Masterclass course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to Fullstack D3 Masterclass, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
[00:00 - 00:18] In this module, we're going to be going through how to build kind of a dashboard or chart library in React using D3. So if you're unfamiliar with React, I highly recommend going through, there's a really nice tutorial linked on their home page.
[00:19 - 00:30] React is basically a declarative component-based JavaScript framework. It makes it really easy to manage dynamic content on the web, and also static content.
[00:31 - 00:52] There's a lot of ways that you can kind of make your life a lot easier as a developer for creating simple to very complex web apps or websites. We're going to be creating our apps using JSX, which is this pseudo HTML language.
[00:53 - 01:05] We're also going to be using React hooks, which came out in 2020. And this should largely mirror a lot of React code bases. It's a very popular library.
[01:06 - 01:21] So again, if you don't know it very well, go ahead and take the tutorial just so you have your bearings before we jump in, because we really want to focus on how you combine D3 and React. There's tons of really great resources for learning React itself.
[01:22 - 01:39] So the first question is, how do we combine React and D3? What's the general principle? The issue is that both React and D3 want to manipulate the DOM and determine what's on the page.
[01:40 - 02:03] You might not like this answer, but really the simplest and least hacky way to combine these kinds of libraries is to totally ignore all of the D3 methods that change anything about the web page. And this might sound really scary, but here we have this visualization of the different modules in D3.
[02:04 - 02:16] And we've talked about a lot of these things already. And really, the only things we need to ignore here are the ones that have to do with manipulating the DOM.
[02:17 - 02:50] So it's this selections library and then this selections multilibrary, which we never even really talked about. All of these other things you can use as this massive utility library and they 're going to help you do things like grab data, manipulate data, draw those SVG shapes, convert data into the physical domain, dealing with colors, dealing with date times, animations, geo, maps and globes, and these more specific visualizations.
[02:51 - 03:10] So it sounds scary and we won't be able to use fully things like D3, access top , bottom, left, right, but you'll see how once we've gotten our bearings, it's actually pretty manageable and hopefully a really enjoyable way to work with D3 and React.