Skip to content

Tag: javascript

Modifying Response of Graphql before sent out

I am looking for a way to modify the response object of a graphql query or mutation before it gets sent out. Basically in addition the the data object, I want to have extra fields like code and message. At the moment I am solving this by adding the fields directly into my GQL schemas take this type definition…

How do I parse a relative URL without base URL in JavaScript

For absolute URL we can parse with new URL(str); for relative URL with base URL we can have new URL(path, base). How do I parse a relative URL without a base URL? For example, folder/file.ext?a=1&b=2#hash should be parsed into Third-party library is fine, but I prefer built-in libraries and functions. Pre…

useMemo vs. useEffect + useState

Are there any benefits in using useMemo (e.g. for an intensive function call) instead of using a combination of useEffect and useState? Here are two custom hooks that work exactly the same on first sight, besides useMemo’s return value being null on the first render: useEffect & useState useMemo Bot…