Last active
June 7, 2018 10:10
-
-
Save samouss/1208a3ca6f83cf7681437a351ce41c7a to your computer and use it in GitHub Desktop.
Custom widget with React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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