Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No render table with new data #14

Open
fonderkin opened this issue Jun 2, 2021 · 1 comment
Open

No render table with new data #14

fonderkin opened this issue Jun 2, 2021 · 1 comment

Comments

@fonderkin
Copy link

fonderkin commented Jun 2, 2021

Component no Re-rendering when load new data.

Example

import BootstrapTreeTable from 'bootstrap-react-treetable';

const Test = () => {
  const [tabValue, setTabValue] = useState(0);
  const handleClick = (n) => () => {
    setTabValue(n);
  };

  const data = React.useMemo(() => {
    switch (tabValue) {
      case 0:
        return {
          tableData: [
            {
              data: {
                name: 'name0',
                dataType: 'string0',
              },
            },
          ],
          columns: [
            {
              dataField: 'name',
              heading: 'name',
            },
            {
              dataField: 'dataType',
              heading: 'dataType',
            },
          ],
        };
      case 1:
        return {
          tableData: [
            {
              data: {
                test: 'test',
                test2: 'test2',
                test3: 'test3',
              },
            },
            {
              data: {
                test: 'test',
                test2: 'test2',
                test3: 'test3',
              },
            },
          ],
          columns: [
            {
              dataField: 'test',
              heading: 'test',
            },
            {
              dataField: 'test2',
              heading: 'test2',
            },
            {
              dataField: 'test3',
              heading: 'test3',
            },
          ],
        };
      default:
        return null;
    }
  }, [tabValue]);

  return (
    <div>
      <button type="button" onClick={handleClick(0)}>
        Tab 1
      </button>
      <button type="button" onClick={handleClick(1)}>
        Tab 2
      </button>
      <div>Table Data {JSON.stringify(data)}</div>
      <BootstrapTreeTable tableData={data.tableData} columns={data.columns} control={{}} />
    </div>
  );
};

export default Test;

Result Tab 1

image

Result Tab 2

image

Expected behavior

Re-rendering when load new data

@eduardoluizgs
Copy link

Me too. Try to update state with a loop, don´t update or re-render the component. Sample:

  async populateData() {
    ...
    let requirements = [];

    await Promise.all(this.state.issues.map(async (issue) => {
      const response = await fetch(`url`, {
        headers: !token ? {} : { 'Authorization': `Bearer ${token}` }
      });
      const content = await response.json();
      requirements = [...requirements, ...content.data || []]

     this.setState({
        requirements: [...this.state.requirements, ...requirements.data],
     });

    }));

    ...
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants