Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle dynamic IDs in examples #17

Closed
oieduardorabelo opened this issue Jun 19, 2017 · 1 comment
Closed

How to handle dynamic IDs in examples #17

oieduardorabelo opened this issue Jun 19, 2017 · 1 comment

Comments

@oieduardorabelo
Copy link

hey guys! :)

i've a few components that generates dynamic internal ids for their children, like:

import shortid from 'shortid';

class Field extends React.Component {
  constructor() {
    this.instanceId = shortid.generate();
  }

  render() {
    return (
      <p>
        <label htmlFor={this.instanceId}>Example<label>
        <input id={this.instanceId} />
      <p>
    )
  } 
}

Every time I start the style guide, I've a few red bars diffing only the ID.

Without moving it to a prop, there's any solution for this issue?

(I'm not worried about it tbh, just asking :P)

@MicheleBertoli
Copy link
Collaborator

Hello @oieduardorabelo, thanks for your question.
Snapshots fail with pseudo-random values or values that change overtime and, apart from mocking the source of randomness, there is no solution.
In this case, as you said, the only way is passing the shortid generator as prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants