You can try this
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
const componentArray = [];
export default function App() {
const formComponents = () => {
data.forEach((d, i) => {
let index = Math.floor(i / 4);
componentArray[index] = [
...(componentArray[index] || []),
<span key={d}>{d}</span>
];
});
console.log(componentArray);
return componentArray;
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
{/* <NewDevicePage /> */}
{formComponents().map((comp, i) => (
<div key={i}>{comp}</div>
))}
</div>
);
}
Hope this helps.