Is there a way to incorporate a transition effect when the button is clicked within this React component? Since the code modifies the JSX content instead of the className, traditional CSS transitions may not work. How can I implement a smooth transition effect in this scenario?
import React, { useState } from 'react';
import ChatItem from './ChatItem';
import ChatButton from './assets/ChatButton';
import classes from './ChatBot.module.css';
const ChatList = (props) => {
const [selected, setSelected] = useState(props.items[0]);
function handleChangeSelected(item) {
setSelected(item);
}
const questionButtons = props.items.map((item) => {
if (item.id === selected.id) return null;
return (
<ChatButton onClick={handleChangeSelected.bind(null, item)}>
{item.question}
</ChatButton>
);
});
return (
<div className={classes.faq}>
<section className="textbox">
<ChatItem
key={selected.id}
id={selected.id}
question={selected.question}
answer={selected.answer}
/>
</section>
<div className={classes.questions}>{questionButtons}</div>
</div>
);
};
export default ChatList;