I am getting this warning
Warning: Tabs: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it
I am already passing key in my component .don't know where I am doing wrong.
here is my code https://codesandbox.io/s/priceless-edison-g09nz?file=/src/App.js
<Tabs>
{data.reduce((result, tabItem, tabIndex) => {
result.push(<Tab {...getTabItemProps(tabItem, tabIndex)} key={tabIndex}/>);
return result;
}, [])}
</Tabs>
Tabs.js
<>
<ul className="rc64nav" ref={tabsRef}>
{tabsVisible.reduce((result, tabItem, tabIndex) => {
result.push(tabItem);
return result;
}, [])}
</ul>
<ul>
<hr/>
<div>break</div>
<hr/>
{tabsHidden.reduce((result, tabItem, tabIndex) => {
result.push(tabItem);
return result;
}, [])}
</ul>
</>
Tab.js
import React from "react";
const Tabs = ({ title,hidden }) => {
return <li className={hidden ? 'hidden':'not-hidden'}>{title}</li>;
};
export default Tabs;
I fixed the error: https://codesandbox.io/s/beautiful-sid-l9753?file=/src/tabs.js.
What I changed:
I added a prop called tabKey. In App.js:
const getTabItemProps = (tabItem, tabIndex) => ({
title: tabItem,
key: tabIndex,
tabKey: tabIndex
});
I made tabs.js reference tabKey instead of trying to use key as a prop:
const { tabKey = index } = tabItem.props;