DEV Community

Cover image for Embed Substack Signup Form in React
Akilesh
Akilesh

Posted on

Embed Substack Signup Form in React

" This article is published using Lamento🍋

I have used substackapi to achieve this Custom Embed Substack Signup Form

Configuration:

substackUrl: "akileshio.substack.com",

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3pvrfr53fhrilrd5g6l.png)

* **theme**: To customize colors you can use pre-defined style `purple`, `orange` or `green` in theme or if you wanted to add your own colors scheme add `custom` in theme and add your colors to `primary, input, email & text`
Enter fullscreen mode Exit fullscreen mode

theme: "custom",
colors: {
primary: "#FFFFFF",
input: "#334155",
email: "#FFFFFF",
text: "#000000",
}


**Here is your final code:**
Enter fullscreen mode Exit fullscreen mode

import React, { useEffect } from 'react';

const SubstackWidget = () => {
useEffect(() => {
// Define the CustomSubstackWidget on the window object
window.CustomSubstackWidget = {
substackUrl: "akileshio.substack.com",
placeholder: "example@gmail.com",
buttonText: "Subscribe",
theme: "custom",
colors: {
primary: "#FFFFFF",
input: "#334155",
email: "#FFFFFF",
text: "#000000",
},
};

// Create a new script element
const script = document.createElement('script');

// Set the source of the script to the Substack widget script
script.src = "https://substackapi.com/widget.js";
script.async = true;

// Append the script to the body
document.body.appendChild(script);

// Cleanup function to remove the script when the component unmounts
return () => {
  document.body.removeChild(script);
}
Enter fullscreen mode Exit fullscreen mode

}, []);

return (


);
};

export default SubstackWidget;


I you want to make your users redirect to custom URL after they signup, visit (substackapi)[https://substackapi.com/] to Unlock  Custom Redirect for $3.99/month.
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

Thanks, this is helpful!

Collapse
 
akilesh profile image
Akilesh

Your welcome, keep an eye out for useful content ☺️

Collapse
 
liamsherwood profile image
Liamsherwood

This did not work for me. In my nextJS project, I use the Custom Substack Embed as you set it up here, as a CSR component which i import elsewhere. The

is empty in my elements tab. Any ideas as to why this could be?