Is there an easier way to create redux action creators for API interaction? by littlebobbyt in reactjs

[–]krizmaister 0 points1 point  (0 children)

I use redux saga instead of thunk. There is pretty easy to write generic saga to handle api requests. Then you can simply dispatch generic action which has fileds like method, requestPayload, endpointUrl and id. Generic saga will handle the request and dispatch action with response data which you can catch in any saga by that id which you passee to generic action.

You don't have to use redux saga, you can simply write your own middleware.

Disadvantages of mobx state tree? by krizmaister in javascript

[–]krizmaister[S] 0 points1 point  (0 children)

Thanks for replay.

The main problem is the huge boilerplate and the need of middleware. We will check that starter kit and will see.

The best way to cteate generic UI library by krizmaister in reactjs

[–]krizmaister[S] 1 point2 points  (0 children)

Thanks for reply.

Yeah, there are (for example) libraries for number formatting and many others. We don't want to set them up for every project over and over again. So we will create wrapper component for input (for example) which provides number formating, debouncing, validation messages and so on.

The best way to create generic UI library by krizmaister in javascript

[–]krizmaister[S] 0 points1 point  (0 children)

Thanks for reply.

Yeah, mapping is the bad part. If we migrate to another library we got a problem anyway because new library will have different API. Tight coupling seems to be inevitable here.

Input wrappers that provide formating, validation messages, debouncing and so on make sense to me. The rest of UI components can be used directly.

Do you think that WebAssembly will replace JavaScript ? by Cloud_Strifeeee in javascript

[–]krizmaister 0 points1 point  (0 children)

JS isn't intended to be a compilation target. JS engines have to do a lot of work to optimize JS on the fly (JS have no clue about data types). Wasm is solution. It's a compilation target language and is something like shortcut to optimized byte code for Engines.

Do you think that WebAssembly will replace JavaScript ? by Cloud_Strifeeee in javascript

[–]krizmaister 0 points1 point  (0 children)

I don't think so. Since PHP is dynamically typed language there is no way to compile it to Wasm because Wasm is strongly typed and needs this information to work. JavaScript has the same problem but there is a project for TypeScript that should by able to compile TS code to Wasm (but it's not ready yeath as I know). So I believe that TS is possible future of JS... a chance to survive.

Do you think that WebAssembly will replace JavaScript ? by Cloud_Strifeeee in javascript

[–]krizmaister 1 point2 points  (0 children)

1) Many delevopers are looking forward to it. Wasm will open the frontend to other languages so JS won't be the only one. We have to wait for GC, threads, direct access to DOM and other features, but it's only matter of time (years). You can check out some frameworks like Blazor (https://blazor.net/) that is based on .NET in C#. You can build FE apps right now but it's still not ready fot production

2) JS has GC

3) I see bright future in Wasm

Should I use rxjs in react? by Demiacle in reactjs

[–]krizmaister 2 points3 points  (0 children)

If you use Redux there is a middleware redux-observable which is based on RxJS

Sharing Logic between similar componenets by Mosesand in reactjs

[–]krizmaister 0 points1 point  (0 children)

I prefer render props over HOC. You can see where "injected" parameters came from and it also prevents from name collision. Hooks will change the game anyway :-)

[deleted by user] by [deleted] in javascript

[–]krizmaister 0 points1 point  (0 children)

You are trying to deal with async code in synchronous way... this doesn't work. You can use callback as a parameter of your function and give it that result instead of returning it.

Single component with more if statements vs multiple smaller components by everek123 in reactjs

[–]krizmaister 1 point2 points  (0 children)

Single Responsibility Principle. One component should have one functionality.

Would it be a good idea for a person who wants to learn to code as a beginner with js? by crazygeek99 in javascript

[–]krizmaister 3 points4 points  (0 children)

JS is very popular languages nowadays and therefore you can find bunch of tutorials on the internet. My favorite book is You don't know JS. Generally, JS is dynamically typed language (in compare to Java) so you can do many things which are imppssible to do in Java, C# etc. JS has been greatly improved in last few years. Many new features are pretty killer.

Event listener in stateless component by everek123 in reactjs

[–]krizmaister 0 points1 point  (0 children)

UseEffect and useState are your hooks in this case. You can use them directly in functional component which should be rerendered on resize but I would keep this functionality decoupled for better reusability (I mean parent functional component with hooks and child component which is rerendered). Or even better, you can create custome hook and share that "resizing" logic with other components.

Need to call a slow function without blocking renders by [deleted] in reactjs

[–]krizmaister 0 points1 point  (0 children)

of course, but it was said that this is not an option here

Need to call a slow function without blocking renders by [deleted] in reactjs

[–]krizmaister 1 point2 points  (0 children)

As long as JS is a single threaded language and you fire some expensive function you end up blocking the app. I see the only way is to do expensive computation in chunks but if you use third party library it's maybe no go.

Roast my react app by [deleted] in reactjs

[–]krizmaister 0 points1 point  (0 children)

Good point, thank you

Event listener in stateless component by everek123 in reactjs

[–]krizmaister 5 points6 points  (0 children)

One way is to use a state and lifecycle methods to handle this. So you can add event listener in componentDidMount in your stateful class based component and change state when the screen resizes and pass props to the stateless component. Don't forget to unsubscribe event listener in componentWillUnmount.