mantinedev / mantine

A fully featured React components library
https://mantine.dev
MIT License
26.3k stars 1.86k forks source link

Defining Tree's data inside a React component together with useTree causes infinite re-render #6916

Open mohammad-reza-rahbar opened 21 hours ago

mohammad-reza-rahbar commented 21 hours ago

Dependencies check up

What version of @mantine/* packages do you have in package.json?

7.13.0

What package has an issue?

@mantine/core

What framework do you use?

Vite

In which browsers you can reproduce the issue?

All

Describe the bug

I spend hours to figure out defining Tree's data inside a React component when using useTree hook causes an infinite re-render!

import { Tree, useTree } from '@mantine/core';

export function Demo() {
  console.log('render');

  const tree = useTree();

  const data = [
    {
      label: 'mantine',
      value: 'mantine',
    },
  ];

  return <Tree data={data} tree={tree} />; 
}

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

mikhail-molchanov commented 6 hours ago

Most likely caused by some state change that happens upon tree controller initialization, in combination with the data array that is re-created from scratch on every render. Little you can do about it except for moving your data outside the component to have a stable reference.