I knew this.refs are deprecated and can change it with React.createRef but in my case is different
This is our code
export default class ScrollableTabString extends Component {
static ITEM_PADDING = 15;
static defaultProps = {
tabs: [],
themeColor: '#ff8800',
};
static propTypes = {
tabs: PropTypes.any,
themeColor: PropTypes.string,
};
shouldComponentUpdate(nextProps, nextState) {
if (nextProps.tabs !== this.props.tabs || this.state !== nextState) {
return true;
}
return false;
}
constructor(props) {
super(props);
this.views = [];
this.state = {};
this.scrollableTabRef = React.createRef();
}
componentDidMount() {
setTimeout(() => {
this.select(this.props.defaultSelectTab ? this.props.defaultSelectTab : 0);
}, 300);
}
select(i, code) {
let key = 'tab ' + i;
for (let view of this.views) {
if (view) {
let isSelected = false;
if (view.key === key) {
isSelected = true;
}
// This refs is Object with many ref views
if (this.refs[view.key]) {
this.refs[view.key].select(isSelected);
}
this.scrollableTabRef.current.goToIndex(i);
}
}
if (this.props.onSelected) {
this.props.onSelected(code);
}
}
render() {
this.views = [];
if (this.props.tabs) {
let tabs = this.props.tabs;
for (let i = 0; i < tabs.length; i++) {
if (tabs[i]) {
let key = 'tab ' + i;
let view = (
<TabItem
column={tabs.length}
themeColor={this.props.themeColor}
useTabVersion2={this.props.useTabVersion2}
isFirstItem={i === 0}
isLastItem={i === tabs.length - 1}
ref={key}
key={key}
tabName={tabs[i].name}
onPress={() => {
this.select(i, tabs[i].code);
}}
/>
);
this.views.push(view);
}
}
}
let stypeTab = this.props.useTabVersion2
? null
: { borderBottomWidth: 0.5, borderColor: '#8F8E94' };
return (
<ScrollableTab
ref={this.scrollableTabRef}
style={Platform.OS === 'ios' ? stypeTab : null}
contentContainerStyle={Platform.OS === 'android' ? stypeTab : null}
>
{this.views}
</ScrollableTab>
);
}
}
I want to fix the warning from eslint but in our case, I can't use React.createRef