I’ve also added a lifecycle method to these Points: when they are first created, they receive a small animation.
To that end, I have also used the component Did Mount method, but this time at the Point level.
In that example, I have used a bona fide (https://org/mbostock/7881887) and wrapped it inside a React component.
So I can create one, or in the case of that example, several such elements by just passing properties.
We just saw that with React, we can create a DOM element, then immediately after, call a function to do whatever we want, such as manipulating that element. We can create components that are, essentially, an SVG element, then use component Did Mount to perform D3 magic on that element.
That function would have access to all the properties and state of that React element. Here’s an example: See the Pen mixing react and d3 by Jerome Cukier (@jckr) on Code Pen.
But it can be really convenient to have that extra degree of control.
The third argument is content: it can either be a string, a single React element, or an array of React elements. So, this first line created a React element which is a span, which contains “hello React world”, and which has a simple style applied to it.Then, each time we click the button, a different data property is passed to the Scatterplot element.Also, the component Did Update method is triggered, which changes the message.That button changes the state of Chart (which causes a rerendering of the Scatterplot and the Point elements).Chart also has a private variable that holds a message we can display on top.