Fork me on GitHub
#om-next
<
2017-02-01
>
alexey_12:02:35

Hi all, creating my first Om Next app—hitting a case where I would like a component to have a custom react-key, and also get props defined by the query. If I pass the props to the factory, the component will have the custom props (`react-key`) on first render, but once a key defined in the query is updated, only the data defined by query is available via props. e.g. when I create the component via factory:

(component {:react-key "abc"})
(om/props this) inside render returns {:rect-key "abc"} but only on the first render.

alexey_12:02:21

If component defines IQuery as, say, [:key1 :key2], once :key1 is updated in the app state, the props are {:key1 "value" :key2 "value"}, the :react-key is gone.

alexey_12:02:10

Is there a way to have both externally passed props and props available via the query?

alexey_12:02:24

Was looking at computed, but that doesn’t seem to do it.

Joe R. Smith15:02:22

@alexey_ You can create a factory with a :keyfn and it’ll use the provided function to calculate the react key. The function could be a keyword naming a prop, or just constantly return some value

Joe R. Smith15:02:06

e.g., (om.next/factory Component {:keyfn (constantly “abc”)})

devth23:02:52

trying to get a component A to re-render itself when another component B updates data that A uses. read about including read keys in the transact! but i'm not sure which key since component A has a nested/complex query (i tried a few).