Skip to main content

Create a slider with the ReactJS and Bootstrap with Dynamic Content of SharePoint List

Create a Dynamic Carousel Slider with React JS and SPFx

Create a Dynamic Carousel Slider with React JS and SPFx

Author: Vishal Thakur

A good presentation increases the chances of impressing your audience. If you are a business owner with an online presence, your application must have a rich user interface and be easy to use. One effective way to share information with end-users is through a carousel slider. It allows you to present information in an engaging, slide-by-slide format, making it visually appealing and interactive.

Introduction

Building a carousel that interacts with dynamic content is a modern approach and as easy as making a cupcake. In this blog, I will show you how to implement a carousel using React JS and Bootstrap in SharePoint/Office 365 SPFx, which interacts with a SharePoint List.

Steps to Follow

If you are new to this, please review the basics by following the guide below:

Implement a Basic Carousel with ReactJS and Bootstrap 4 in Just 10 Minutes

Create a SharePoint List

If you are an experienced developer, this will be straightforward. For beginners, it’s as easy as drinking a coconut. Below is an example of the list I created:

The columns used in the list are:

  • Title: Single Line of Text
  • Description: Multiline of Text
  • RedirectURL: Hyperlink
  • ImageURL: Hyperlink

Install All the Dependencies

First, run the following command to scaffold the SPFx project:

yo @microsoft/sharepoint

After selecting React JS as the framework, run the following commands to install the required dependencies:

npm i --save react-bootstrap
npm install bootstrap@4 --save
npm install @types/bootstrap@4 --save
npm install jquery --save
npm install @types/jquery --save
gulp build

Copy the Code

Once all dependencies are installed, open the TSX file and add the following imports:

import Carousel from 'react-bootstrap/Carousel';
import "bootstrap/dist/css/bootstrap.css";
import * as jQuery from 'jquery';
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';

Next, define an interface for the list columns:

export interface ISliderCarouselListItem {
  Title: string;
  Description: string;
  ImageURL: [];
  RedirectURL: [];
}

Then, implement the API to interact with the SharePoint List:

private getCarouselListContent = () => {
  try {
    let requestUrl = `${this.props.absoluteURL}/_api/web/Lists/GetByTitle('${this.props.listName}')/Items`;
    this.props.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1)
    .then((response: SPHttpClientResponse): Promise<ISliderCarouselDemoState> => {
      if (response.ok) {
        return response.json();
      }
    }).then((item) => {
      if (item != null) {
        this.setState(({
          value: item.value
        }));
      }
    });
  } catch (error) {
    console.log('error in service ', error);
  }
}

Conclusion

By following the above steps, you can create a beautiful and functional carousel slider that interacts with a SharePoint List. React JS provides flexibility and an optimized way to communicate with SharePoint Lists and third-party APIs.

For more advanced carousel implementations, you can explore the following libraries:

I hope this guide helps you. Please share your feedback in the comments section.

Thank you! :)

For more tutorials, visit my blog: The Ultimate Resources.

Comments

Popular posts from this blog

Power Apps modern driven app Interview Question and answer

Power Apps Modern Driven App: Questions and Answers Power Apps Modern Driven App: Questions and Answers Power Apps modern driven apps are low-code/no-code platforms that enable users to create custom applications. Below are some common questions and detailed answers to help you understand their capabilities and applications. Question 1: What is a Power Apps modern driven app? Answer: A Power Apps modern driven app is a low-code/no-code application development platform provided by Microsoft. It allows users to create custom applications that can run on various devices and platforms without extensive coding. These apps are built using a visual interface and can integrate with different data sources. Question 2: What are the key components of a Power Apps modern driven app? Answer: The key components of a Power Apps modern driven app are: Screens: Serve as the user interface for the app, including layouts, ...

Create self signed SSL certificate

How to Create a Self-Signed SSL Certificate for React JS Using mkcert How to Create a Self-Signed SSL Certificate for React JS Using mkcert A self-signed certificate is a digital certificate that is created and signed by the same entity it identifies. Unlike certificates issued by trusted Certificate Authorities (CAs), self-signed certificates aren't verified by external parties. They're commonly used for local development, testing, or internal systems where the identity verification provided by a CA is not necessary. Although self-signed certificates can secure communication, they lack the third-party validation provided by CA-signed certificates, and users may encounter browser warnings when accessing websites using self-signed certificates. In this guide, we’ll walk you through the steps to create a self-signed SSL certificate for your React JS application using mkcert . Step 1: Install Chocolatey ...

SPFX Interview question for 2023

SPFx Interview Questions for 2023 SPFx Interview Questions for 2023 Author: Vishal Thakur Question 1: What is SharePoint Framework (SPFx)? Answer: SharePoint Framework (SPFx) is a development model introduced by Microsoft for creating client-side web parts and extensions for SharePoint Online and SharePoint 2019. It is based on modern web technologies like JavaScript, TypeScript, and React, providing a rich and responsive user experience. I am Vishal Thakur – Founder of TheUltimateResources.com . 🚀 TheUltimateResources is rapidly growing in the IT industry with a team of 100+ professionals , focused on building simple, powerful, and secure digital tools. We’ve recently launched a set of tools designed to solve real-world problems for developers and everyday users. 🔹 SecureDiff – Fast & Secure Comparison Tool 🔗 https://secure...