You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In reactive FE libraries like React, mutating deeply nested data can make it difficult to sync the UI with the data. For example, setting a new fee mutates the auth property,
Even explicitly setting the data may not be sufficient,
functionhandleFeeChange(newFee){transaction.setFee(newFee);// mutates inner propsetTransaction(transaction);// outer transaction object still has same ref. equality}
Even after the above code, transaction has the same referential equality, which prevents memos from running or components from rendering.
Solution
Having a functional approach which avoids mutations would help with reactive UI frameworks.
Currently, the only way to preserve reactivity seems to be with something like
const[auth,setAuth]=useState(transaction.auth);// fee is stored in this objectfunctionhandleNewFee(newFee){transaction.setFee(newFee);setAuth(transaction.auth);}return<div>{auth.fee}</div>
which is suboptimal since transaction is no longer the source of truth for fee, and it's all to easy to accidentally reach out for transaction.auth.fee in a reactive context and break the UI.
The text was updated successfully, but these errors were encountered:
Problem
In reactive FE libraries like React, mutating deeply nested data can make it difficult to sync the UI with the data. For example, setting a new fee mutates the
auth
property,stacks.js/packages/transactions/src/transaction.ts
Lines 236 to 238 in 2cf886b
Even explicitly setting the data may not be sufficient,
Even after the above code,
transaction
has the same referential equality, which prevents memos from running or components from rendering.Solution
Having a functional approach which avoids mutations would help with reactive UI frameworks.
The API could look something like,
Workaround
Currently, the only way to preserve reactivity seems to be with something like
which is suboptimal since
transaction
is no longer the source of truth forfee
, and it's all to easy to accidentally reach out fortransaction.auth.fee
in a reactive context and break the UI.The text was updated successfully, but these errors were encountered: