Skip to main content

React Component

The site-search-360-react component adds a Site Search 360 search box and button to a React app, with the configuration in your code.

The component is no longer developed: its last version, 0.3.3, is from 2022. It loads script v14, expects React 17, and doesn't use your Design & Publish configuration. For new projects, add the Design & Publish snippet to your app's page instead.


Install it​

npm install site-search-360-react

or

yarn add site-search-360-react

import SiteSearch360 from 'site-search-360-react';

<SiteSearch360 siteId="yoursite.com" />

// or without JSX
React.createElement(SiteSearch360, { siteId: 'yoursite.com' });

Use your own site ID, from Account → General → Your Site ID.


Props​

PropWhat it doesDefault
siteId (string)Your site ID. You can also set it in ss360Config.—
ss360Config (object)Your configuration; see Advanced Parameters for the settings.—
showButton (boolean)Shows a search button next to the box.true
applyStyling (boolean)Sets data-ss360 on the element around the box, so the script styles the box and button.true
alias (string)Names the instance, for several search boxes with their own configurations.—

Several instances​

Give each component its own alias. The configuration then goes to window.ss360Configs[alias], and the instance is available as window[alias]:

<SiteSearch360 siteId="yoursite.com" alias="SS360mysite1" ss360Config={config1} />
<SiteSearch360 siteId="yoursite.com" alias="SS360mysite2" ss360Config={config2} />

In that instance's ss360Config, a callback can then address it by its alias:

callbacks: {
init() {
setTimeout(() => window.SS360mysite1.showResults('*'), 1);
}
}

See Multiple Search Boxes for other ways to run several searches on one page.


Gatsby​

The component also works in Gatsby, for example in your layout:

import React from "react"
import { useStaticQuery, Link, graphql } from "gatsby"
import SiteSearch360 from 'site-search-360-react';

export default function Layout({ children }) {
const data = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
}
}
}`
);
return (
<div>
<Link to={`/`}>
<h3>{data.site.siteMetadata.title}</h3>
</Link>
<Link to={`/about/`}>
About
</Link>
<SiteSearch360 siteId="yoursite.com" />
{children}
</div>
);
}