sy-torii
sy-torii

Reputation: 65

Error: App(...): Nothing was returned from render. This usually means a return statement is missing

I have a component in React which I am importing in index.js, but it is giving this error. My goal is to show my Table.js data with react-router-dom at "/". I tried to search and find similar question but I couldn't find how to resolve. Maybe App.js is not correct. Please tell me how to resolve if you know.

enter image description here

Table.js

import React from 'react';
import MaterialTable from 'material-table';
import CheckListService from '../services/CheckList';
import { useEffect } from 'react'
import { useState } from 'react';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';
import Box from '@material-ui/core/Box';
import { makeStyles } from '@material-ui/core';

//日本語化設定
const localizationJapanese = {
    error: "エラー",
    body: {
        emptyDataSourceMessage: "表示するレコードがありません。",
        filterRow: {
            filterPlaceHolder: "",
            filterTooltip: "フィルター",
        },
        editRow: {
            saveTooltip: "保存",
            cancelTooltip: "キャンセル",
            deleteText: "この行を削除しますか?",
        },
        addTooltip: "追加",
        deleteTooltip: "削除",
        editTooltip: "編集",
    },
    header: {
        actions: "編集・削除",
    },
    grouping: {
        groupedBy: "グループ化:",
        placeholder: "ヘッダーをドラッグ ...",
    },
    pagination: {
        firstTooltip: "最初のページ",
        firstAriaLabel: "最初のページ",
        previousTooltip: "前のページ",
        previousAriaLabel: "前のページ",
        nextTooltip: "次のページ",
        nextAriaLabel: "次のページ",
        labelDisplayedRows: "{from}-{to} 全{count}件",
        labelRowsPerPage: "ページあたりの行数:",
        lastTooltip: "最後のページ",
        lastAriaLabel: "最後のページ",
        labelRowsSelect: "行",
    },
    toolbar: {
        addRemoveColumns: "列の追加、削除",
        nRowsSelected: "{0} 行選択",
        showColumnsTitle: "列の表示",
        showColumnsAriaLabel: "列の表示",
        exportTitle: "出力",
        exportAriaLabel: "出力",
        exportCSVName: "CSV出力",
        exportPDFName: "PDF出力",
        searchTooltip: "検索",
        searchPlaceholder: "検索",
        searchAriaLabel: "検索",
        clearSearchAriaLabel: "クリア",
    },
};

//footer
function Copyright() {
    return (
        <Typography variant="body2" color="textSecondary" align="center">
            {'Copyright © '}
            <Link color="inherit" href="https://material-ui.com/">
                株式会社ウィラム. All rights reserved.
        </Link>{' '}
            {new Date().getFullYear()}
            {'.'}
        </Typography>
    );
}

//独自CSS
const useStyles = makeStyles({
    root: {
        marginTop: '100px',
        marginBottom: '100px',

    }
});

export const Table = () => {
    const classes = useStyles();
    const [dataAll, setDataAll] = useState([]);
    useEffect(() => {
        CheckListService.getList().then((response) =>
            setDataAll(response.data)
        )
    }, [])

    const columns = [
        {
            title: 'リスト番号', field: 'listNo'
        },

        {
            title: 'ソフトウェア名', field: 'softwareName'
        },
        {
            title: '採用日', field: 'saiyouDate'
        },
        {
            title: 'バージョン', field: 'version'
        },
        {
            title: '種別', field: 'shubetu'
        },
        {
            title: 'ライセンス', field: 'licenseManage'
        },
        {
            title: '用途', field: 'youto'
        },
        {
            title: '備考', field: 'bikou'
        },
        {
            title: '承認者', field: 'authorizer'
        },
        {
            title: '承認日', field: 'approvalDate'
        },
        {
            title: 'URL', field: 'url'
        }
    ]
    return (
        <div>
            <div className="container">
                <div className={classes.root}>
                    <MaterialTable
                        title="使用許可ソフトウェアリスト"
                        data={dataAll}
                        columns={columns}
                        style={{
                            marginTop: '50px',
                            whiteSpace: 'nowrap',
                        }}
                        options={{

                            headerStyle: {
                                backgroundColor: '#75A9FF',
                                color: '#FFF'
                            }

                        }}
                        localization={localizationJapanese}

                        actions={[
                            {
                                icon: 'edit',
                                tooltip: '編集',
                                onClick: (event, rowData) => window.confirm(rowData.softwareName + "を編集しますか?")
                            },
                            {
                                icon: 'delete',
                                tooltip: '削除',
                                onClick: (event, rowData) => window.confirm(rowData.softwareName + 'を削除しますか?')
                            }
                        ]}
                    />

                </div>
            </div>
            <Box pt={4}>
                <Copyright />
            </Box>
        </div>
    )


}

App.js

import './App.css';
import { Table } from "./components/Table";
import React, { Component } from 'react'
import { BrowserRouter, Route, Link } from 'react-router-dom'


const App = () => {
  <BrowserRouter>
    <div>

      <Route exact path="/" component={ShowTable} />
    </div>

  </BrowserRouter>
}

const ShowTable = () => {

  return (
    <div>
      <Table />
    </div>
  );
}

export default App;

Index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: 
reportWebVitals();

Upvotes: 0

Views: 6870

Answers (1)

Dennis Vash
Dennis Vash

Reputation: 53894

As the error states, return statment is missing in App:

const App = () => {
  // Add return statement
  return (
    <BrowserRouter>
      <div>
        <Route exact path="/" component={ShowTable} />
      </div>
    </BrowserRouter>
  );
};

Or:

const App = () => (
  <BrowserRouter>
    <div>
      <Route exact path="/" component={ShowTable} />
    </div>
  </BrowserRouter>
);

Upvotes: 3

Related Questions