react-native-best-viewpager icon indicating copy to clipboard operation
react-native-best-viewpager copied to clipboard

Strange component example in docs

Open Saniol opened this issue 3 years ago • 0 comments

Currently docs suggest creating separate methods in class component to render specific parts - e.g.:

 class ViewPagerPage extends Component {
    ...
    _renderDotIndicator() {
        return <PagerDotIndicator pageCount={3} />;
    }

It would work, but that way basically you're defining functional component _renderDotIndicator as method of ViewPagerPage. That's not really "React way" of splitting your code, you should rather define separate components like:

const DotIndicator = () > (<PagerDotIndicator pageCount={3} />)

In most cases it would be just about keeping code clean and following best React practises, but sometimes there might be some serious implications - e.g. if you'll try to use ref inside one of those methods ( _renderDotIndicator, _renderTitleIndicator, _renderTabIndicator) it work (as functional components have to be wrapped with React.forwardRef() before they can use ref).

Saniol avatar Mar 08 '21 15:03 Saniol