Skip to content

Conversation

@varchasvakhare2022
Copy link

@varchasvakhare2022 varchasvakhare2022 commented Nov 18, 2025

Description

This PR fixes issue #89 by moving the renderSearchSuggestion function outside the SearchSuggestions component definition to prevent creating a new function on each render.

Problem

Previously, renderSearchSuggestion was defined inside the SearchSuggestions component, which meant a new function was created every time the component re-rendered. This is inefficient and can cause unnecessary re-renders of child components.

Solution

Moved renderSearchSuggestion outside the component definition so it's only created once and reused across renders.

Changes

  • Moved renderSearchSuggestion function definition above SearchSuggestions component
  • Updated code example in patterns/15.list-components.md

Beforeript

const SearchSuggestions = (props) => {
const renderSearchSuggestion = listItem => (

  • {listItem.name} {listItem.id}

  • );
    // ...
    };

    Afterscript

    const renderSearchSuggestion = listItem => (

  • {listItem.name} {listItem.id}
  • );

    const SearchSuggestions = (props) => {
    // ...
    };

    Fixes #89

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    List components

    1 participant