Skip to content

Instantly share code, notes, and snippets.

@samouss
Last active June 7, 2018 10:10
Show Gist options
  • Save samouss/1208a3ca6f83cf7681437a351ce41c7a to your computer and use it in GitHub Desktop.
Save samouss/1208a3ca6f83cf7681437a351ce41c7a to your computer and use it in GitHub Desktop.
Custom widget with React
const CustomWidget = createWidget({
widget: {
render({ state, helper }) {
const refine = () => {
const next = state.query === "" ? "Apple" : "";
helper.setQuery(next).search();
};
return {
currentRefinement: state.query,
refine
};
}
}
});
const App = () => (
<CustomWidget>
{({ refine, currentRefinement }) => (
<p>
<button onClick={refine}>
{currentRefinement ? "Clear" : 'Search for "Apple"'}
</button>
</p>
)}
</CustomWidget>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment