Fix state change after unmount (#2653)
This commit is contained in:
parent
fca768ca46
commit
833e759b49
1 changed files with 13 additions and 7 deletions
|
@ -27,21 +27,27 @@ const BoardTemplateSelectorPreview = (props: Props) => {
|
|||
const [activeTemplateCards, setActiveTemplateCards] = useState<Card[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
let isSubscribed = true
|
||||
if (activeTemplate) {
|
||||
setActiveTemplateCards([])
|
||||
setActiveView(null)
|
||||
setActiveTemplateCards([])
|
||||
octoClient.getAllBlocks(activeTemplate.id).then((blocks) => {
|
||||
const cards = blocks.filter((b) => b.type === 'card')
|
||||
const views = blocks.filter((b) => b.type === 'view').sort((a, b) => a.title.localeCompare(b.title))
|
||||
if (views.length > 0) {
|
||||
setActiveView(views[0] as BoardView)
|
||||
}
|
||||
if (cards.length > 0) {
|
||||
setActiveTemplateCards(cards as Card[])
|
||||
if (isSubscribed) {
|
||||
const cards = blocks.filter((b) => b.type === 'card')
|
||||
const views = blocks.filter((b) => b.type === 'view').sort((a, b) => a.title.localeCompare(b.title))
|
||||
if (views.length > 0) {
|
||||
setActiveView(views[0] as BoardView)
|
||||
}
|
||||
if (cards.length > 0) {
|
||||
setActiveTemplateCards(cards as Card[])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return () => {
|
||||
isSubscribed = false
|
||||
}
|
||||
}, [activeTemplate])
|
||||
|
||||
const dateDisplayProperty = useMemo(() => {
|
||||
|
|
Loading…
Reference in a new issue