preact#isValidElement TypeScript Examples

The following examples show how to use preact#isValidElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: header.ts    From gridjs with MIT License 6 votes vote down vote up
static fromColumns(
    columns: OneDArray<TColumn | string | ComponentChild>,
  ): Header {
    const header = new Header();

    for (const column of columns) {
      if (typeof column === 'string' || isValidElement(column)) {
        header.columns.push({
          name: column,
        });
      } else if (typeof column === 'object') {
        const typedColumn = column as TColumn;

        if (typedColumn.columns) {
          typedColumn.columns = Header.fromColumns(typedColumn.columns).columns;
        }

        // because the data for that cell is null
        // if we are trying to render a plugin
        if (typeof typedColumn.plugin === 'object') {
          if (typedColumn.data === undefined) {
            typedColumn.data = null;
          }
        }

        // TColumn type
        header.columns.push(column as TColumn);
      }
    }

    return header;
  }