score:41
Accepted answer
simplest solution: use alias.
const link = ({
to,
classname,
onclick,
target,
rel,
key,
'data-navbar-click': datanavbarclick,
}) => {
const test = datanavbarclick;
};
datanavbarclick should have the value "close-menu"
score:2
you can write a utility function that transforms camelcase
key names to kebab/hyphen-case properties, picked them out out of the props object and, by using jsx spread, render them in the component.
example below:
import kebabcase from 'lodash/kebabcase';
const props = {
datanavattr: 'close-menu',
itemcount: 100
}
const pickandtransformdataprops = (props, findbykey) => {
const pickedprops = {};
object.keys(props).map(key => {
if (key.includes(findbykey)){
pickedprops[kebabcase(key)] = props[key];
}
});
return pickedprops;
}
const pickeddataprops = pickandtransformdataprops(props, 'data');
console.log({ pickeddataprops });
// using jsx spread: <component onclick={props.onclick} { ...pickeddataprops } />
Source: stackoverflow.com
Related Query
- How to access data attributes from event object
- How to destruct `data-*` (hyphen cased) attributes from props?
- How to fetch data from api and pass it as props
- How to handle the props from Parent Component to child component to populate props data in the form for updation
- How to pass on data that are fetched from Firestore as props to a component
- How to take out props data from a component in react-js?
- How can i pass data from promise to props in react
- How to get custom data attributes values in `MenuItem` from `Select` in material ui?
- How to pass data received from database as props to another component in Reactjs
- React & TypeScript how pass data from child to parent at onClick via props
- How to pass data from one variable in props to another in React app?
- How to extract data from json and pass as props in Next.js
- How to pass data to props from state?
- how to get the updated data from parent to child as props
- How do I set the current component state from the data received as props from the parent component?
- How to pass data received from a database as props to another component in react
- How to get props and pass data from child in reactjs?
- How to pass data from a long fetch call function as props in React
- How can I match data from an object and pass it as props to another component that displays dynamically?
- how to control the img attributes src in fetching the data from database in Reactjs
- How can i pass data from parent to child using props
- React : how to show my data from props in my menus section
- how to pass the data from data.json file in react components with the help of props in react js?
- How to set dynamic attributes in React Input Component from json props
- how to fetch data from webservice in REACT useEffect function and send it to props object?
- How to fetch data from api already in props using MDBDataTable
- How to pass data from child component to its parent in ReactJS?
- How to access custom attributes from event object in React?
- How get data from material-ui TextField, DropDownMenu components?
- Reactjs: how to modify dynamic child component state or props from parent?
More Query from same tag
- override react native style
- Summing up prices of user's cart from 2 arrays
- Why doesn't 100vh fill whole page?
- React render method that depends on asynchronous request and state change
- ReactJS .... map() is not a function
- How to Render a page / component in UseEffect?
- Modal using Bootstrap doesn't update content
- Test mousedown event
- Typing an array of objects as props in React
- Database SQL design
- SecurityError: localStorage is not available for opaque origins with new testEnvironmentOptions.url option
- Functional Components: Accessing Shared States
- Wildcard matching in a React if statement?
- Passing a function thact changes state to child component
- Getting two warnings with my useEffect function reactJS
- Get all images from specific directory via GraphQL and Gatsby JS
- Best way to access aync function returns
- mongoose.connect undefined is not a function
- How to create a ref and manually trigger onclick on a textfield in React hooks
- Checking prop types in React
- How to precompile scss to a single css file in webpack?
- ReferenceError: anchorEl is not defined
- Why react not render false
- Is there a search engine friendly way to combine server side rendered HTML with a client side MVVM/MVC framework?
- jsconfig and jest not interacting to use same root paths
- Inject dynamic content react
- getting blob from image and sending to server react
- How to open Drop Down only if in input entered required keyword?
- Test component with mock React Jest
- How to clear the preview image in form on submit but display it in the web page without any problem in React?