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.

variables for propTypes

See original GitHub issue

Hi, im using oneOf(myArray). The problem is because myArray is a variable and declared above the component.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
khankuancommented, Mar 25, 2016

sample snippet

const types = ['dark', 'light'];
...
static propTypes = {
  types: React.PropTypes.oneOf(types)
}

This resulted in the value being ‘types’ as a string. It would be nice if we can replace it with the variable value instead of the variable name.

1reaction
leepowelldevcommented, Mar 17, 2019

Sorry to raise an old issue, but should this work if the values are kept in an imported file?

import { types } from './types';
...
static propTypes = {
  types: React.PropTypes.oneOf(types)
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typechecking With PropTypes - React
PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, ... We'll add a prop variable that returns either the propFullName or the key ....
Read more >
Specify Types of Props With PropTypes - Intermediate React
We're going to import PropTypes from the library and use Card. propTypes to specify the type for each of the properties.
Read more >
What should be the prop type of passing a variable down in a ...
As I can see your someValue is foobar which is string, so it should be PropTypes.string · yes, but where? – Remi ·...
Read more >
Mastering Props And PropTypes In React - Smashing Magazine
This tutorial will introduce you to the details about props, passing and accessing props, and passing information to any component using props.
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