import React, { useEffect } from ‘react’; var scheduler = require (‘./scheduler.js’); function CASchedulesList(props) { const columnData = [{ headerName: ‘Name’, field: ‘name’ }, { headerName: ‘Start Time’, field: ‘start_time’ }, { headerName: ‘Created On’, field: ‘created_on’ }, { headerName: ‘Last Modified’, field: ‘last_modified’ }, { headerName: ‘Status’, field: ‘status’ }, { headerName: ‘Task List’, field: ‘task_list’ }]; const agColumnData = columnData.slice(0); agColumnData.shift(); var agRowData = Array(); useEffect(() => { setInterval(function(){ var scheduleData = JSON.parse(scheduler.allSchedules).schedules; for (let i = 0; i < scheduleData.length; i++) { agRowData[i] = { selected: false, name: scheduleData[i].name, start_time: scheduleData[i].start_time, created_on: scheduleData[i].created_on, last_modified: scheduleData[i].last_modified, status: scheduleData[i].status, task_list: ‘test’ }; } console.log(agRowData); },1000); }, []); const rowData = agRowData.slice(0).map(item => { item.control = true; return item; }); return ( <div class = ‘grid-zone’> <rux-table> <rux-table-header> <rux-table-header-row> {columnData.map((column, index) => (<rux-table-header-cell>{column.headerName}</rux-table-header-cell>))} </rux-table-header-row> </rux-table-header> <rux-table-body> {rowData.map((row, index) => ( <rux-table-row selected={row.selected}> <rux-table-cell>{row.name}</rux-table-cell> <rux-table-cell>{row.start_time}</rux-table-cell> <rux-table-cell>{row.created_on}</rux-table-cell> <rux-table-cell>{row.last_modified}</rux-table-cell> <rux-table-cell>{row.status}</rux-table-cell> <rux-table-cell>{row.task_list}</rux-table-cell> </rux-table-row> ))} </rux-table-body> </rux-table> </div> ); } export default CASchedulesList;
The console.log (agRowData) outputs succesfully and it is in the correct format to be displayed in the table, but the table renders too soon before the data has been imported from the other script which is getting it from a websocket. So no matter what happens the table always stays empty. How can I force it to re-render?
submitted by /u/elijahsalberg
[link] [comments]