om-next

alexey_ 2017-02-01T12:53:35.000972Z

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_ 2017-02-01T12:55:21.000974Z

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_ 2017-02-01T12:57:10.000976Z

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

alexey_ 2017-02-01T12:57:24.000977Z

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

alexey_ 2017-02-01T12:57:27.000978Z

Thanks.

2017-02-01T15:56:22.000984Z

@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

👍 2
🙏 2
2017-02-01T15:58:06.000985Z

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

devth 2017-02-01T23:48:52.000996Z

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).