ValentinH / react-easy-sort

A React component to sort items in lists or grids
https://ValentinH.github.io/react-easy-sort
MIT License
160 stars 25 forks source link

Give example with component child #41

Closed 1ncredibleM1nd closed 10 months ago

1ncredibleM1nd commented 10 months ago

In documentation you wrote, that for using SortableList with custom component need using forwardRef I tried to write this code:

  <SortableList
                    onSortEnd={onSortEnd}
                    className="slider-settings__slides list"
                    draggedItemClassName="dragged"
                >
                    {items.map((st, index) => (
                        <SortableItem key={st.id}>
                            <SortableImage
                                ref={ref}
                                id={st.id}
                                index={index}
                                src={st.src}
                            />
                        </SortableItem>
                    ))}
                </SortableList>

Component SortableImage

const SortableImage = forwardRef(({ id, src, index, ref }: IProps) => {
    return (
        <div key={id} ref={ref} className="slider-settings__wrapper">
            <div className="slider-settings__slide">
                <button className="slider-settings__dnd-btn dragHandle">
                    <img src={drag} alt="" />
                </button>
                <button className="slider-settings__delete-btn">
                    <img src={close} alt="" />
                </button>
                <img className="slider-settings__img" src={src} />
            </div>
            <p className="slider-settings__count">{++index}</p>
        </div>
    );
});

Help me

ValentinH commented 10 months ago

What is not working with this?

1ncredibleM1nd commented 10 months ago

All working, my mistake... Refs have been dropped to props, sorry. Close issue, please