react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Add `Promise<void>` as a type for onSelect and onSelectAll functions to be able to use async-await.

Open HarshitaVishwakarma opened this issue 3 years ago • 0 comments

I am using bootstrap-table-next made for typescript, and trying to implement the checkbox mode for the table rows as follows

const selectRow: SelectRowProps<any> = {
        mode: "checkbox",
        clickToSelect: false,
        classes: "selection-row",
        onSelect: async (row, isSelect, rowIndex, e) => {
            if(isSelect){
                //do something with the row data
                //I want to call a method that returns a promise 
               const data = await returnSomeData(row.id)
               //do something with the returned data     
            }
        },
        onSelectAll: async (isSelect, rows, e) => {
            let cards: any[] = [];
            if(isSelect){
                rows.forEach((row, rowIndex) => {
                     //do something with the row data
                     //I want to call a method that returns a promise 
                     const data = await returnSomeData(row.id)
                    //do something with the returned data
                })
            }
        }
    };

Currently async-await does not work for onSelect and onSelectAll and give the following errors if I add async before the function call as I have done in the above example:

  1. Type Promise<void> is not assignable to type boolean | void (onSelect)
  2. Type Promise<void> is not assignable to type void | number[] (onSelectAll)

Could you please also add the Type Promise<void> for the 2 callback functions so we can also use async-await inside the callback functions

I am not sure if there's a reason why this feature isn't there at the moment, if there's a specific reason for not having this, please let me know.

The alternative solution I tried is to use when-then way of calling the async function but I am facing scope issues when it comes to multiple rows.

I would really appreciate it if this feature could be possible.

HarshitaVishwakarma avatar May 18 '22 11:05 HarshitaVishwakarma