While trying to render a functional component and trying to truncate a large paragraph on a map item using item.biography.substr(0, 20).
I have tried different syntaxes without success. Will appreciate any help. Here is my component.
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
import axios from 'axios';
import $ from 'jquery';
//import "./styles.css";
function Instructor() {
const [page, setPage] = useState(1);
const [data, setData] = useState(['a', 'b', 'c']);
const [isLoading, setIsLoading] = useState(true);
const loadMoreData = () => {
setPage(page + 1);
};
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'http://www.localhost/ulearn/api/getInstructors',
);
setData(result.data);
};
fetchData();
}, []);
return (
<div>
<h1> API FOR INSTRUCTOR COMPONENT </h1>
{isLoading && <p>Wait I'm Loading comments for you</p>}
{data.length !== 0 && (
<button onClick={loadMoreData}>Load More Data</button>
)}
{data.map((item, index) => (
<div className="col-xl-3 col-lg-4 col-md-6 col-sm-6" key={index}>
<div className="instructor-box mx-auto text-center">
<a href="{{ route(d.view, d.instructor_slug) }}">
<main>
<div className="col-md-12">
<h6 className="instructor-title">{item.first_name}
{item.last_name}
`enter code here`</h6>
<p> {item.biography.substr(0, 20)} </p>
</div>
</main>
</a>
</div>
</div>
))}
</div>
);
}
if (document.getElementById('instructor')) {
ReactDOM.render(<Instructor />, document.getElementById('instructor'));
}