React hooks useCallback with parameters inside loop

The simple answer here is, you probably shouldn’t use useCallback here. The point of useCallback is to pass the same function instance to optimized components (e.g. PureComponent or React.memoized components) to avoid unnecessary rerenders. You’re not dealing with optimized components in this case (or most cases, I’d suspect) so there’s not really a reason to … Read more

How to validate a string literal type using zod

I commented that this might be a duplicate since the core of the question could be solved with z.literal, but it is a bit different. Just to illustrate what you can do: import { z } from ‘zod’; const PaymentTypeSchema = z.union([ z.literal(‘CHECK’), z.literal(‘DIRECT DEPOSIT’), z.literal(‘MONEY ORDER’), ]); type PaymentType = z.infer<typeof PaymentTypeSchema>; const schema … Read more

Display PDF in reactJS

If you goal is just to view the pdf in your application, the easiest way is using the object tag in HTML. You don’t need to import any libraries and works most of the browsers. But this is lack of customization and styles. <object data=”http://africau.edu/images/default/sample.pdf” type=”application/pdf” width=”100%” height=”100%”> <p>Alternative text – include a link <a … Read more

Redux – handling really large state object

I’ll elaborate on the excellent answer by @phry. Instead of configuring the ignored paths, you could just increase the timeouts: const store = configureStore({ // … middleware: (getDefaultMiddleware) => getDefaultMiddleware({ immutableCheck: { warnAfter: 128 }, serializableCheck: { warnAfter: 128 }, }) }) or turn off the checks altogether: const store = configureStore({ // … middleware: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)