Advertisement
Guest User

Untitled

a guest
May 18th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. useEffect(() => {
  2. if (!containerRef.current) {
  3. return undefined;
  4. }
  5.  
  6. const search = autocomplete({
  7. container: containerRef.current,
  8. plugins: [recentSearchesPlugin],
  9. renderer: { createElement, Fragment, render: () => {} },
  10. render({ children }, root) {
  11. if (!panelRootRef.current || rootRef.current !== root) {
  12. rootRef.current = root;
  13.  
  14. panelRootRef.current?.unmount();
  15. panelRootRef.current = createRoot(root);
  16. }
  17. panelRootRef.current.render(children);
  18. },
  19. renderNoResults({ state }, root) {
  20. if (!panelRootRef.current || rootRef.current !== root) {
  21. rootRef.current = root;
  22.  
  23. panelRootRef.current?.unmount();
  24. panelRootRef.current = createRoot(root);
  25. }
  26. panelRootRef.current.render(
  27. <div className="p-3">No results for "{state.query}"</div>
  28. );
  29. },
  30. onSubmit: (event) => {
  31. event.preventDefault();
  32. console.log(event.currentTarget);
  33. },
  34. ...props,
  35. });
  36.  
  37. return () => {
  38. search.destroy();
  39. };
  40. }, [props]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement