0

Here is my code for a React Where I am maping an array of objects but get Error [ Expected an assignment or function call and instead saw an expression ] so please help how can I do solve this issue..? In my code I want to map data to bootstrap 4 carousel slider code , in my data I have photo,name,achievement so how can I map 3 of It..!

import React, { useState, useEffect } from "react";
import web from "../../image/nisha.jpg";
import web1 from "../../image/Pooja.jpg";
import web2 from "../../image/6547.jpg";
import { isAutheticated } from "../../auth/helper/index";
import { getTestis } from "../helper/coreapicalls";
import "../../styles.scss";
import ReactReadMoreReadLess from "react-read-more-read-less";

const Testimonial1 = () => {
  const [testimonial, setTestimonial] = useState([]);
  const [error, seterror] = useState([]);
  const [loading, setLoading] = useState(false);
  const token = isAutheticated() && isAutheticated().token;
  const userId = isAutheticated() && isAutheticated().user.email;

  useEffect(() => {
    loadTestimonial();
  }, []);

  const loadTestimonial = () => {
    getTestis().then((data) => {
      if (data.error) {
        seterror(data.error);
      } else {
        setTestimonial(data);
        console.log(data);
      }
    });
    setLoading(true);
  };
  console.log(testimonial);
  return (
    <div>
      <h1 className="blog_heading">Testimonials</h1>
      <div className="testimonial">
        <div
          id="carouselExampleSlidesOnly"
          className="carousel slide"
          data-ride="carousel"
        >
          <div className="carousel-inner active container">
            {testimonial.map((testi, index) => {
              <div className="carousel-item active" key={index}>
                <div className="testimonial_content">
                  <a href={web}>
                    <img
                      src={web}
                      alt="img"
                      className="rounded-circle img-fluid "
                    />
                  </a>
                  <h1>{testi.name}</h1>

                  <p>
                    <sup>
                      <i
                        className="fa fa-quote-left mr-2"
                        style={{ fontSize: "14px", color: "#ffca08" }}
                        aria-hidden="true"
                      ></i>
                    </sup>
                    <ReactReadMoreReadLess
                      charLimit={200}
                      readMoreText={"Read more ▼"}
                      readLessText={"Read less ▲"}
                      readMoreStyle={{ color: "#00ba74", fontSize: "15px" }}
                    >
                      {testi.achievement}
                    </ReactReadMoreReadLess>
                  </p>
                </div>
              </div>;
            })}
          </div>
        </div>
      </div>
    </div>
  );
};

export default Testimonial1;

enter image description here

8
  • 5
    You need a return in the map function homie Commented Feb 11, 2021 at 16:36
  • 1
    "please help how can I do solve this issue..?" - First you have to help us. What line triggers the error, what's the exact error message -> How do I ask a good question? Commented Feb 11, 2021 at 16:37
  • Line 45:15: Expected an assignment or function call and instead saw an expression @Andreas Commented Feb 11, 2021 at 16:38
  • As you might have noticed there are no line numbers in code blocks. And no, we're not going to count them to find the correct line... ;) Commented Feb 11, 2021 at 16:40
  • {testimonial.map((testi, index) => { ..})} line @Andreas Commented Feb 11, 2021 at 16:55

1 Answer 1

1

Just replace your map code with this:

testimonial.map((testi, index) => {
              return (
                     <div className="carousel-item active" key={index}>
                <div className="testimonial_content">
                  <a href={web}>
                    <img
                      src={web}
                      alt="img"
                      className="rounded-circle img-fluid "
                    />
                  </a>
                  <h1>{testi.name}</h1>

                  <p>
                    <sup>
                      <i
                        className="fa fa-quote-left mr-2"
                        style={{ fontSize: "14px", color: "#ffca08" }}
                        aria-hidden="true"
                      ></i>
                    </sup>
                    <ReactReadMoreReadLess
                      charLimit={200}
                      readMoreText={"Read more ▼"}
                      readLessText={"Read less ▲"}
                      readMoreStyle={{ color: "#00ba74", fontSize: "15px" }}
                    >
                      {testi.achievement}
                    </ReactReadMoreReadLess>
                  </p>
                </div>
              </div>;
              )
            })
Sign up to request clarification or add additional context in comments.

2 Comments

hi, @kunal I am getting my all data on a single slide
thanks, please with this question stackoverflow.com/q/66156615/15160538 ,@kunal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.