M
M
MarEeeeeee2021-04-07 17:49:27
PHP
MarEeeeeee, 2021-04-07 17:49:27

Do I get an error when using useState?

I'm trying to implement some functionality using useState, but as soon as I include a line in the code, I start getting an error
const [ currVal, setCurrVal ] = React.useState(0);

default.a.useState is not a function or its return value is not iterable

I can't figure out what's wrong.
useState import from 'react'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
eternalfire, 2018-05-25
@eternalfire

It is good practice to write a layer or intermediate model between the controller and the model, which contains all the business logic.
It is also called a service
. That is, the controller manages the service, which in turn pulls the model.

T
ThunderCat, 2018-05-25
@ThunderCat

There are many approaches, and all have their advantages and disadvantages. I usually break it down into sane "physical" entities: address, phone, company, mail... in this case joins in the collections of belongings can quickly change the method of relations from one to many to many to many by simply adding a link table. There will also be only 2-3 minor edits in the logic. Keeping everything in one table/entity is the worst option.

S
Sergey, 2018-05-25
@red-barbarian

The idea of ​​MVC, MVP, MVVM, etc. is to separate the business model from the ui. Those. business model should not care what kind of controller there will be, and so on.
so talking about the model and looking back at the controller is a signal that something is wrong with our architecture.
Further, to reduce confusion in the future))) it is better to describe the business logic in the entities of the subject area. For example
Company
Category
Address
etc
Implementation should be hidden.
In total, the choice of the two presented models comes down to which model is closer to the subject area:
Category.give aList
of Organizations Organization.give aList of Addresses
or
Company.give
aList of Categories Company.give aList of Addresses
In fact, the difference is only in the first line. And the difference is that it is more often used: the dependence of categories on organizations or vice versa. More often, it should be easier to implement. if two dependencies are needed, two cases must be implemented in the model.
I note that the implementation of storing business logic objects should be hidden behind the repository type interface. It will issue ready-made entities regardless of the database or data fetch.
It's kind of like this. Although no one forbids cutting corners by reducing the number of layers in the architecture or interfaces. ))) You just need to understand that by doing this we increase the number of connections between parts of the system, but reduce the amount of code written. The balance depends on the case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question