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, ...

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. Question 2: What are the key advantages of using SPFx for SharePoint development? Answer: SPFx offers several advantages, such as: Responsive and mobile-ready web parts and extensions. Seamless integration with SharePoint data and services. Support for modern web development practices and tools. Easy deployment and hosting options. Enhanced security and isolation through the SharePoint app model. Question 3: Can you explain ...

Interview Questions of SPFx SharePoint

SPFx Interview Questions and Scenarios SPFx Interview Questions and Scenarios By Vishal Thakur What is SPFx? The SharePoint Framework (SPFx) is a web part model that provides full support for client-side SharePoint development. It integrates seamlessly with SharePoint data and extends Microsoft Teams. SPFx allows developers to use modern web technologies and tools in their preferred development environment to build responsive and mobile-ready experiences. Scenario-Based Questions Scenario 1: External API Integration Scenario: Your team is developing an SPFx web part that needs to retrieve data from an external API and display it on a SharePoint site. The API requires authentication using OAuth 2.0. The web part should also allow users to refresh the data manually. Question: How woul...