D
D
Denis Sokolov2020-11-22 22:48:36
React
Denis Sokolov, 2020-11-22 22:48:36

How to make a modal window with changing information in it?

I have a component with a modal window and a component with entries. I need a window with the necessary information to open when the button is clicked.

export const CardNews = ({ active, setActive, ...props }) => {
return (
    <div className="news-card">
        <div className="news-card__content">
            <div className="news-card__img">
                <img src={image_1} alt="img" className="news-card__image" />
            </div>
            <div className="news-card__text">
                <div className="news-card__title">{props.title}</div>
                <div className="news-card__descr">{props.descr}</div>
                <button className="check-news" id={props.id} onClick={() => setActive(true)}>
                    Читать
                </button>
            </div>
        </div>
    </div>
)
}

export const Modal = ({active, setActive, ...props}) => {
 return (
     <div className={active ? "modal active" : "modal"} id={props.id} onClick={() => setActive(false)}>
         <div className={active ? "modal-overlay active" : "modal-overlay"}>
             <div className="modal-window" onClick={(e) => e.stopPropagation()}>
                 <div className="modal-header">
                     <div className="modal-header__title">{props.title}</div>
                     <div className="modal-header__close" onClick={() => setActive(false)}>&times;</div>
                 </div>
                 {props.children}
             </div>
         </div>
     </div>
 )
}

const dataBasePost = [
{
    "id": "1",
    "title": "Объявление",
    "shortDescr": "Мы работаем со следующими поставщиками"
},
{
    "id": "2",
    "title": "Внимание",
    "shortDescr": "Мы работаем со следующими поставщиками"
}
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-11-22
@0xD34F

https://jsfiddle.net/mwoLsdr7/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question