score:109
You should not wrap JavaScript expressions in quotes.
<option data-img-src={this.props.imageUrl} value="1">{this.props.title}</option>
Take a look at the JavaScript Expressions docs for more info.
score:32
Note - if you want to pass a data attribute to a React Component, you need to handle them a little differently than other props.
2 options
Don't use camel case
<Option data-img-src='value' ... />
And then in the component, because of the dashes, you need to refer to the prop in quotes.
// @flow
class Option extends React.Component {
props: {
'data-img-src': string
}
And when you refer to it later, you don't use the dot syntax
render () {
return (
<option data-img-src={this.props['data-img-src']} >...</option>
)
}
}
Or use camel case
<Option dataImgSrc='value' ... />
And then in the component, you need to convert.
// @flow
class Option extends React.Component {
props: {
dataImgSrc: string
}
And when you refer to it later, you don't use the dot syntax
render () {
return (
<option data-img-src={this.props.dataImgSrc} >...</option>
)
}
}
Mainly just realize data-
attributes and aria-
attributes are treated specially. You are allowed to use hyphens in the attribute name in those two cases.
Source: stackoverflow.com
Related Query
- How do I dynamically set HTML5 data- attributes using react?
- How to assert a div in a React component's data attributes using Enzyme?
- How to set data in child component dynamically by using props in React?
- How to set graphql data using react hooks in typescript?
- How to set state at the server for data from API using react redux
- how to fetch api data dynamically on the basis of click using react js
- React JS (Form Update Not Working) - How to set state immediately after getting data from API using mapDispatchToProps?
- How to map deep JSON data dynamically using React
- How to fix map is not function even there is already set data in the useState using React Hook
- How to set local JSON data as state using hooks React
- How to dynamically set prop names using react functional components
- How to provide dynamically calculated data in table using react and redux
- How to set React to production mode when using Gulp
- How can I pass data using <Redirect> in react router v4?
- how to set state array using react hooks
- How to Cache API data using AsyncStorage React Native
- How to set headers for a React app created using 'create-react-app'
- How to paste clipboard data using React Testing Library?
- How to set value dynamically inside Form.List using setFieldsValue in Antd 4?
- How to assign value dynamically to TextInput using react native
- How to set multiple values at once in react hook form using Typescript
- React how to dynamically set div height to follow suit of full window height including scroll
- How do I access data returned from an axios get to display on a web page using react js?
- How do you pass data when using the navigate function in react router v6
- How to extract data to React state from CSV file using Papa Parse?
- How to set route with optional query parameter using React router?
- How to set initial tab in react navigation TabNavigator dynamically
- How to set timeout in Fetch API using react js
- How to export data to excel using react libraries
- How to disable HTML5 validation in React using formsy-react?
More Query from same tag
- Spring API request giving "Content type 'application/octet-stream' not supported" error, however request is successful when using Postman
- How to properly test React Native Modals using Jest and Native Testing Library
- Date picker month / year doesn't work on iOS
- Render Component inside a different location
- How does react keep variables value in useCallback?
- How to set a background image for all pages in reactjs
- React Js API call Unit Test Case
- How Can I use the returned string (new feature of React v16.0.0) in the source tag of an image ex: <img src='returnedString' />?
- Pass boolean to expected react-element component props in material-ui list-item
- How do I add type definitions for React's useContext?
- Is it possible to switch the value of a css property using an if statement in styled-components?
- start page in center on first boot ReactJs
- React new project dependency on ^6.14.0 || ^8.10.0 || >=9.10.0
- update is not capturing and unable to update the input field
- Navigate programmatically in React router 4 with mix of function/class components & TypeScript
- ReactJS - Can not return jsx for callback function?
- How to display the information submitted in the html form on another page using react js?
- AntDesign Cascader: error Not found value in options
- Right way of using react-hook-form with typescript and material-ui for showing error message
- add item to cart page with react ( only with this.state )
- Redux Saga - Unable to cancel task
- How to get data from server and use a hook to retrieve it in multiple components?
- react js form inputs using eval?
- running frontend and backend on different ports
- Date validation in Formik: 'Date of purchase' must be earlier than 'Date of sale'
- React conditional re-rendered not triggered
- Is there a react date picker that allows two week view?
- In nightwatch.js moveToElement() is deprecated. I want to move pointer to a offset and doubleClick on that. How to go forward with this?
- Dynamic rendering in React
- Resolving multiple versions of React in component library built with Webpack and Storybook