Пропустить навигацию
⚛️ I don't like baking app or business logic directly in components.
0:00 / 0:44

⚛️ I don't like baking app or business logic directly in components.

George Moller

@_georgemoller118 тыс. подписчиков

Открыть в X
804 отметки «Нравится»СкачатьОригинальный пост

57 116 просмотров

⚛️ I don't like baking app or business logic directly in components. Instead, I use useReducer hook to separate the business logic from the UI. ✅ More predictable state changes ✅ Better architecture↓

10 комментариев

Комментарии из оригинального поста в X (Twitter)

  • Фото профиля George Moller

    @_georgemoller

    I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

    6 отметок «Нравится»

  • Фото профиля React Nuclear

    @reactnuclear

    “Business logic” shouldn’t start with “use” because why would your business logic have anything to do with react?

    6 отметок «Нравится»

  • Фото профиля JonhBoy

    @JonhBoy8

    Why not a hook for this?

    4 отметки «Нравится»

  • Фото профиля anto

    @justize28

    I should probably use useReducer more often but usestate is easier for me to read

    1 отметка «Нравится»

  • Фото профиля George Moller

    @_georgemoller

    Fair enough, when you get used to use reducer I’d argue it’s easier to read, follow, debug and even test than useState.

  • Фото профиля skai

    @brownRasgulla

    Do you put the reducer function in the component file or in a separate file?

    1 отметка «Нравится»

  • Фото профиля George Moller

    @_georgemoller

    It depends really, if it gets too large yeah sure I separate that in a file, otherwise I like colocating the reducer in the component and exporting it from there to test it.

    1 отметка «Нравится»

  • Фото профиля Nandakishor Pg

    @nandhu_pg

    seperate file for use reducer?

    1 отметка «Нравится»

  • Фото профиля Pavel Romanov

    @pavl_ro

    That's how it should be done. To be honest, I would even try to move this business logic to backend whenever possible.

    1 отметка «Нравится»

  • Фото профиля George Moller

    @_georgemoller

    Agree whenever possible keep that in the backend!

    1 отметка «Нравится»