Extending result item component
Prerequisite
Setup for development with typescript
Steps to extend
Create a components directory in the designated react folder.
Create a React component file (e.g. CustomItem.tsx)
Open the file to edit and import React and ResultItemProps
import React from 'react'; import { ResultItemProps } from 'react-hawksearch';
Â
Create the component function
function CustomItem({ item }: ResultItemProps) { // Configuration goes here }
Â
For the configuration, declare all the fields that are gone be used in this component
let title = item.getDocumentValue('title'); let content = item.getDocumentValue('content');
Â
The component function should return the structure
Â
Export the component
Â
Save the file.
Open the results component file for editing.
Import the newly created item component
Locate the Results component initialization. It should be in the App structure.
Â
Set the ResultItem prop to point to the item component
Â
Save and re-build the JS resources.
Â
Examples
Creating a custom item for dynamic layout based on content type (e.g. components/ContentTypeDynamicItem.tsx)
Â