Spectacle: React Presentation Framework
Spectacle is an actively maintained, ReactJS-powered library for creating interactive and dynamic presentations. As of version 10.2.3, it provides a comprehensive suite of React components (e.g., `Deck`, `Slide`, `FlexBox`, `Heading`) that enable developers to build highly customizable slideshows using standard web technologies. The library typically receives regular patch and minor updates, addressing bug fixes and introducing new features like the recent `FitText` component in v10.2.0. Spectacle differentiates itself by allowing the full power of React and its ecosystem to be leveraged for presentation design, offering a developer-centric alternative to traditional presentation software and enabling complex animations, data visualizations, and interactive elements directly within slides.
Common errors
-
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
cause Incorrectly importing Spectacle components, e.g., using `import Component from 'spectacle';` instead of `import { Component } from 'spectacle';`.fixEnsure all Spectacle components are imported as named exports: `import { Deck, Slide } from 'spectacle';`. -
TypeError: Cannot read properties of undefined (reading 'Fragment')
cause React version mismatch. Spectacle versions >=10.2.2 require React 18 or higher. If your project uses an older React version, this error can occur.fixUpgrade your project's `react` and `react-dom` dependencies to `^18.0.0` or higher to match Spectacle's peer dependency requirements. Example: `npm install react@^18 react-dom@^18`. -
Module not found: Error: Can't resolve 'spectacle' in '...' OR `ReferenceError: exports is not defined`
cause Mixing CommonJS `require()` syntax with an ESM-first library, or incorrect module resolution configuration in older bundlers.fixEnsure your project is configured for ESM and use `import { ... } from 'spectacle';` syntax. If using webpack, ensure `resolve.fullySpecified: false` is not set or that your `tsconfig.json` `module` option is appropriate (e.g., `esnext`, `node16`).
Warnings
- breaking Spectacle v10.2.2 replaced `defaultProps` with the `attrs` method for React 19 compatibility. While primarily an internal change, consumers relying on direct access or manipulation of `defaultProps` on Spectacle components in older versions (pre-10.2.2) may experience unexpected behavior or build failures when upgrading to React 19. Ensure you are on Spectacle `10.2.2` or newer for React 19 support.
- gotcha The `create-spectacle` CLI tool, used for scaffolding new projects, was updated in `create-spectacle@0.4.0` to use an ESM/import map-based one-page setup. Older `create-spectacle` versions might generate projects with outdated configurations or module resolution patterns.
- gotcha Spectacle requires `react` and `react-dom` as peer dependencies. Mismatched versions between Spectacle and your project's React installation (e.g., Spectacle expecting React 18 but your project using React 17) can lead to various runtime errors, including issues with hooks or rendering.
- gotcha The `Heading` component's secondary color styling was inadvertently lost in v10.2.2 due to the internal `defaultProps` replacement. This was fixed in v10.2.3. If using v10.2.2, your headings might not apply the correct theme color.
Install
-
npm install spectacle -
yarn add spectacle -
pnpm add spectacle
Imports
- Deck
const { Deck } = require('spectacle');import { Deck, Slide, Heading, Text } from 'spectacle'; - FlexBox
import FlexBox from 'spectacle';
import { FlexBox } from 'spectacle'; - createTheme
import * as spectacle from 'spectacle'; const theme = spectacle.createTheme(...);
import { createTheme } from 'spectacle';
Quickstart
import React from 'react';
import {
Deck,
Slide,
Heading,
Text,
Box,
FlexBox,
createTheme,
} from 'spectacle';
const theme = createTheme(
{
primary: 'white',
secondary: '#1F2022',
tertiary: '#03A9F4',
quaternary: '#CECECE',
},
{
primary: 'Inter',
secondary: 'Helvetica',
}
);
function Presentation() {
return (
<Deck theme={theme}>
<Slide backgroundColor="primary">
<Heading color="secondary">Welcome to Spectacle!</Heading>
<Text color="tertiary">
A ReactJS Powered Presentation Framework
</Text>
</Slide>
<Slide backgroundColor="secondary">
<FlexBox height="100%" flexDirection="column" justifyContent="center" alignItems="center">
<Heading fontSize="h2" color="primary">Key Features</Heading>
<Box margin="20px 0">
<Text color="quaternary">๐ฅ Full React Ecosystem</Text>
<Text color="quaternary">๐จ Highly Customizable Themes</Text>
<Text color="quaternary">๐ Interactive Slides</Text>
</Box>
</FlexBox>
</Slide>
<Slide backgroundColor="tertiary">
<Heading fontSize="h3" color="primary">Get Started</Heading>
<Text color="secondary">
Install with `npm install spectacle react react-dom`
</Text>
<Text color="secondary">
Then run your React app!
</Text>
</Slide>
</Deck>
);
}
export default Presentation;