Mire esto, al cerrar una pestaña en particular, cierra todas las pestañas que están abiertas. Solo quiero que se cierre esa pestaña en particular.
remove = targetKey => { let { activeKey } = this.state; let lastIndex; this.setState(prevState => { const newState = {...prevState}; newState.forEach((pane, i) => { if (pane.key === targetKey) { lastIndex = i - 1; } }); const panes = newState.filter(pane => pane.key !== targetKey); if (panes.length && activeKey === targetKey) { if (lastIndex >= 0) { activeKey = panes[lastIndex].key; } else { activeKey = panes[0].key; } } return ({panes, activeKey}); }); };Consulte este enlace https://jsfiddle.net/yjumr4ox/1/
El problema es que está iterando sobre todo el estado en newState.forEach y newState.filter . Debe iterar sobre los paneles en el estado. como esto:
remove = targetKey => { let { activeKey } = this.state; let lastIndex; this.setState(prevState => { const newState = {...prevState}; newState.panes.forEach((pane, i) => { if (pane.key === targetKey) { lastIndex = i - 1; } }); const panes = newState.panes.filter(pane => pane.key !== targetKey); if (panes.length && activeKey === targetKey) { if (lastIndex >= 0) { activeKey = panes[lastIndex].key; } else { activeKey = panes[0].key; } } return ({panes, activeKey}); }); };