【发布时间】:2021-01-09 06:21:18
【问题描述】:
在将react-kanban 用于我的项目之前,我正在对其进行测试。我在codesandbox.io 创建了这段代码。
import React,{useEffect , useState} from 'react'
import Board, { addCard } from '@lourenci/react-kanban'
import '@lourenci/react-kanban/dist/styles.css'
export default function Index() {
const [board, setBoard] = useState({
columns: [
{
id: 1,
title: 'Backlog',
cards: [
{
id: 1,
title: 'Add card',
description: 'Add capability to add a card in a column'
},
]
},
{
id: 2,
title: 'Doing',
cards: [
{
id: 2,
title: 'Drag-n-drop support',
description: 'Move a card between the columns'
},
]
}
]
}
)
const addcard =(e)=>{
const newBoard = addCard(board,1,{
id: 3,
title: "dfdfdfdff",
description: "SDfsfsf"
})
setBoard(newBoard)
}
useEffect(() => {
console.log("fetch packages")
}, [])
return (
<div>
<button onClick={addcard} >Add Card</button>
<Board>{board}</Board>
</div>
)
}
挑战是我正在使用他们的助手将卡片添加到板上的列中,但它返回错误。我做错了什么?还是一个错误?
TypeError
Cannot read property 'cards' of undefined
提前感谢您的帮助。
【问题讨论】:
标签: javascript reactjs use-state