score:1
Accepted answer
no, you can't. you can't have mycomp
component and add an attribute to div
element without passing a prop
or even a ref
.
in those scenarios, you should add another wrapper element and apply those attributes to it.
export default function wrapper({children}) {
return (
<div data-value="5">
{children}
</div>
);
}
<wrapper>
<mycomp/>
</wrapper>
Source: stackoverflow.com
Related Query
- React - get the first node of a component?
- How to pass in a react component into another react component to transclude the first component's content?
- Get the current path in a react component
- Can't get the target attributes of material-ui select react component
- React - Get the ref present in child component in the parent component
- How to get the react component instance corresponding to event.target element in a click handler?
- react - how do I get the size of a component child elements and reposition them
- How to get the DOM node from a Class Component ref with the React.createRef() API
- Which is the right way to detect first render in a react component
- I am looking for a way to fix the first column in a table component in react material-ui
- What is the simplest way of testing that a React Component contains a html node with enzyme?
- Use React Portal to render a child into a DOM node of the parent component
- How to get the first and last visible date in React Big Calendar?
- React custom Hook using useRef returns null for the first time the calling component Loads?
- Axios get request returns undefined for the first time in React
- React - Get the component name in functional components
- Get the height of a Component in React
- How do I get the dom node of a child element in a component without adding logic to its parent/children?
- How to get the length of the text inside the React component
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- React router redirects the page but component doesn't get rendered
- How can I use useEffect in React to run some code only when the component first mounts, and some other code whenever an event occurs (repeatedly)?
- In React what's the best way to render a Component differently the first time it appears on the page?
- how to get a Component variable from another component but their both in the same file React
- In react class component why is the state not being changed in the first instance of button click? But in the second instance it gets updated?
- Get access to the chart.js component instance in React
- How to get the id of a react material-ui component
- My button needs to be clicked twice to render the new component for the first click React
- Get React Hook Value from outside the functional component
- In React JS I'm trying to create a countdown timer but can't get the first second to be a full second
More Query from same tag
- Firebase Storage "Permission denied" error
- How to get a value form a child component to a parent component in reactjs?
- React Router: this.props.params not updated after Link click
- All child elements inheriting onclick event from parent div on React
- Javascript, ReactJs setState not working
- Appveyor not running the build script
- Stubbing method in same file using Sinon
- React input slider Hooks
- Significance of using const in render to store state values
- Unable to implement image transition in react with styled-components
- reactjs app fetch() returning mobile html
- Remove a component onClick in react
- How to limit Material UI Autocomplete multiple selections to one group
- ReactJS project on Android WebView, Image not showing
- react I want the white space to disappear before the menu is displayed
- React router not rendering the component on click of a Array item
- Supporting a minimum width on a website
- Need to Manipulate pixels extracted from an image, im using p5.js and react
- How to make Cypress wait for undetermined amount of XHR requests
- Get File type in react js
- Get specific state value when using custom Hooks ( trying to implement a form handling with hooks)
- Extending base class property in Typescript
- React, Divs inside ternary condition are not rendering
- How do you style the grouping rows when you group rows in React-Data-Grid?
- pass multiple refs to child components
- Unit test for attribute fails, only meant to be run on a single node?
- How can I sort the given array?
- node-sass-chokidar doesn't install on npm install
- Basic Reactjs - error with a function
- Correct way to use ref with Next.js for a Link and an <a>?