Giter Club home page Giter Club logo

Comments (4)

cee-chen avatar cee-chen commented on May 28, 2024

So I used, EuiErrorBoundary as well but it couldn't catch the error.

EuiErrorBoundary catches errors thrown by JS code due to developer implementation or API issues - it does not catch errors due to user input. Basically, if an error message doesn't appear in your devtools console, EuiErrorBoundary won't catch it.

Can you suggest some usage or work around to catch the error from EuiSearchBar or in its filters.

Your required onChange callback passes back any errors in the error key. If you really want to use EuiErrorBoundary for this, simply throw any caught errors, for example:

const searchBarOnChange = ({ query, queryText, error }) => {
  if (error) throw new Error(error);
  // Do something with the query
};

<EuiSearchBar onChange={searchBarOnChange}) />

from eui.

Harshav0423 avatar Harshav0423 commented on May 28, 2024

Thanks @cee-chen , but i have already raising the error when there is a change in the SearchBar input, const onChange = ({ query, error }) => { throw new Error("this will cause searchbar error")
https://github.com/Harshav0423/nextjs-eui/blob/main/src/app/components/search.jsx

from eui.

cee-chen avatar cee-chen commented on May 28, 2024

Ah, sorry, you're right. Throwing an error from the onChange won't trigger EuiErrorBoundary, what you need to do is store the error in state and then add a useEffect that throws on error change. This will cause a rerender and EuiErrorBoundary to correctly update.

Example:

const [error, setError] = useState();

const searchBarOnChange = ({ query, queryText, error }) => {
  if (error) setError(error);
  // otherwise do something with the query
};

useEffect(() => {
  if (error) throw new Error(error.message);
}, [error]);

return (
  <EuiErrorBoundary>
    <EuiSearchBar onChange={searchBarOnChange} />
  </EuiErrorBoundary>
);

from eui.

Harshav0423 avatar Harshav0423 commented on May 28, 2024

Thanks for that, I used react-error-boundary to catch any rendering errors. Replaced the EuiSearchbar to EuiBasicTable and wrapped ErrorBoundary around that, so that when there is an error in rendering the table it is going to catch that.

from eui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.