简体   繁体   中英

React + .jsx + Spread Operator — Add a Style?

I have a React element (courtesy of the excellent Downshift library) that looks like this:

<mySearchResults
    {...{
        inputValue,
        selectedItem,
        highlightedIndex,
        getItemProps,
    }}
/>

I need to add a .jsx style to it:

 style: styles.searchResultsContainer

I've tried a couple ways of adding it, including:

<mySearchResults
    {...{
        inputValue,
        selectedItem,
        highlightedIndex,
        getItemProps,
        style: styles.searchResultsContainer
    }}
/>

It builds and runs without errors, but it doesn't seem to get the styles into the element.

What is the correct syntax for this?

That should be correct. Are you sure your mySearchResults component is set up to accept a style prop?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM