I am trying to make a component in React that is just a function
JavaScript
x
13
13
1
import React from "react";
2
3
function TableSortFunction(data, method, column) {
4
const newList = [];
5
for (let i; i <= data.length; i++) {
6
newList.push(data[i].column);
7
}
8
console.log(newList), data, method, column;
9
return newList;
10
}
11
12
export default TableSortFunction;
13
I am importing my function in another component like this
JavaScript
1
2
1
import { TableSortFunction } from "./TableSortFunction";
2
but I get an error saying:
JavaScript
1
2
1
Attempted import error: 'TableSortFunction' is not exported from './TableSortFunction'.
2
How do I export a js file that is just a function?
Advertisement
Answer
Since you export it as default you have to import it like so:
JavaScript
1
2
1
import TableSortFunction from "./TableSortFunction";
2
Edit: Another issue with your code is that the following is not syntactically correct.
JavaScript
1
2
1
console.log(newList), data, method, column;
2
Try this instead:
JavaScript
1
2
1
console.log(newList, data, method, column);
2