标签: reactjs typescript react-hooks
我有以下钩子:
const [textToFront, setTextToFront] = useState('');
当我调用setTextToFront时,我看到旧状态已清除,我想实现简单的事情,我只想在钩子上创建一个大String并显示。如何存储新状态并将其添加到旧状态?
setTextToFront
答案 0 :(得分:2)
尝试
setTextToFront(`${textToFront}${newAppendedText}`);