A
A
anriko2021-11-06 19:57:48
React
anriko, 2021-11-06 19:57:48

How to store the length of the resulting array not in this.state in the class?

when an array of tasks arrives and this is the main one, then I take it from the sections, tasks, into one continuous array and in the renderer, and I give out the finished jsx in a cycle, now I started paginating and I need its length, but I can’t change the state from the renderer, there will be a cycle, then how to get a solid array so that its length is available not only in the function, but in the whole class?
I don’t want to run it every time to get the length of the list, I thought that I could take out the first cycle, but I would also have to run it to find out the length, so I wanted to save it, but how to run this function before rendering or how to save the value during rendering?

forTaskListschild = () => {
        let tasklistitem = [];
        var i = 0;
        let listtask = [];

        for (let tasklistskey in this.state.TaskLists) {
            debugger;
            listtask = [...listtask, ...this.state.TaskLists[tasklistskey].itemlist];
        }
        listtask = listtask.sort((a, b) => b.time - a.time);

        for (let i = 0; i < listtask.length; i++) {
            debugger;
            let keyitem = listtask[i].key;
            let keychapter = listtask[i].keychapter;
            tasklistitem.push(
                <TaskItem data={listtask[i]} keychapter={keychapter} keyitem={keyitem} key={keyitem} index={i}
                    attrdata={this.state.locationPathname === undefined ? "all" : this.state.locationPathname}
                />
            )
        }
        return tasklistitem;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question