просто useEffect активирует setFilteredData, что дает:
`
Код: Выделить всё
{
links: [
{
color: 'red'
},
],
nodes: [
{
focused: focused
},
],
};
`
Надеюсь, мой вопрос ясен. Если нужно что-то добавить или что-то непонятно, просто скажите мне.
Код: Выделить всё
const [filteredData, setFilteredData] = useState();
const LINK_COLOR = "grey";
const LINK_FOCUS_COLOR = "red";
useEffect(() => {
const filterData = () => {
setFilteredData({ links: links, nodes: allNodes });
};
filterData() ;
}, [...]);
const focusLinkId = currentLink ? currentLink.id : "";
const focusNodeId = currentNode ? currentNode.id : "";
const graphData = {
...filteredData,
links: [
...filteredData?.links,
{
color: filteredData?.links?.map((l) => {
const color = l?.id === focusLinkId ? LINK_FOCUS_COLOR : LINK_COLOR;
return color;
}),
},
],
nodes: [
...filteredData?.nodes,
{
focused: filteredData?.nodes?.map((n) => {
const focused = n?.id === focusNodeId;
return focused;
}),
},
],
};
console.log("graphData:", graphData);
Подробнее здесь: https://stackoverflow.com/questions/735 ... l-iterator
Мобильная версия