question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Advanced step control

See original GitHub issue

Following the discussion on #177, a feature I would love to have is an advanced form of Appear that would give great control on what happens at each step (i.e. not necessarily only making a component appear, but anything really).

My main use case is the control of D3.js updates, like filtering some data on a step, highlighting one particular bar, etc.

Original idea

My original idea was a Higher Order Component:

import withSteps from 'mdx-deck/with-steps'

withSteps(numberOfSteps, ({ step }) => {
  // Render something using step.
  return <span>Current step: {step}</span>
})

The above is just a functional component, but withSteps would also allow relying on componentDidUpdate to perform some low-level DOM operations, like updating a D3 chart:

import withSteps from 'mdx-deck/with-steps'

withSteps(numberOfSteps, class Chart extends React.Component {
  constructor(props) {
    super(props)
    this.svgNode = React.createRef()
  }
  componentDidUpdate() {
    const { step, data } = this.props
    updateChart(this.svgNode.current, data, step)
  }
  render() {
    return <svg ref={this.svgNode} />
  }
})

However, as mentioned by @zcei, the issue with this approach is that it is not supported in mdx. As a result, it would require to create the component in a separate file (https://github.com/jxnblk/mdx-deck/issues/177#issuecomment-427588751).

step and setStep as properties

Instead, @zcei suggests a simple component that would provide step and setStep to its child (https://github.com/jxnblk/mdx-deck/issues/177#issuecomment-427579253):

<Steps>
  {({ step, setSteps }) => {
     // Do something with step and setSteps
  }}
</Steps>

However, I believe passing setSteps as a property is a bit weird. With functional components, it makes them intrinsically impure. Also, when should setSteps be called? If the child is a functional component, that means it can only be called at render time 😵… And what happens if one calls setSteps with a value lower than step?

totalSteps on the parent, and setStep as a property

After some thoughts, an alternative could be:

<Steps totalSteps={4}>
  {({ step }) => {
     // Do something with step
  }}
</Steps>

Note that I really wish <Steps> would not only accept functional components but also class component. This is necessary to support low level DOM operations. Maybe:

<Steps totalSteps={4}>
  {class SomeThing extends React.Component { /* */ }}
</Steps>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jxnblkcommented, Apr 20, 2019

V2 now has a useSteps hook that you can use in custom components. I’ll be adding docs soon, but peek at the source code for Appear in the meantime

1reaction
QuentinRoycommented, Oct 8, 2018

Yes absolutely. The point is to make lifecycle hooks available.

I don’t think it is hard to do either. I don’t think a new dependency is required for this. I emphasized it just to make sure it does not get lost.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Step Motor Control - Performance Motion Devices
A broad look at controlling step motors, including basic operating theory, and then introduce a range of new motion control techniques.
Read more >
Stepper Motor Driver and Controller Systems – High Precision ...
Advanced Micro Systems products are used in a wide variety of applications. Below are just a few areas where you'll find our products:....
Read more >
Advanced Control Systems MCU-2 Step Pak Motor Control
Find many great new & used options and get the best deals for Advanced Control Systems MCU-2 Step Pak Motor Control at the...
Read more >
Step & Direction - ADVANCED Motion Controls
Step & Direction. Adopted from stepper motor control, this command method uses two digital inputs to control motion. One input typically increments position ......
Read more >
Advanced-step multistage nonlinear model predictive control
In this paper, we propose a parallelizable advanced-step multistage NMPC (as-msNMPC), which provides a non-conservative robust control solution that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found