Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it possible to get a rum component by data-reactid attribute value? #48

Closed
pbaille opened this issue Oct 14, 2015 · 7 comments
Closed

Comments

@pbaille
Copy link

pbaille commented Oct 14, 2015

I'm working on a mixin that inject styles into component and sub-component
this mixin takes a function that take the component state and return a style hash-map and possibly another hash-map of type sub-element-selector -> style-function and so on
for the moment I use dommy for the sub-element-selectors and get raw HTMLelements , i would like to be able to get the value of the rum element that is mounted on in order to feed the corresponding style-fn. I really hope that it is understandable

Is there a way to get a list of all sub rum components of a rum component?

@tonsky
Copy link
Owner

tonsky commented Oct 15, 2015

Is there a way to get a list of all sub rum components of a rum component?

No, there’s no standard way. It’s application-specific.

i would like to be able to get the value of the rum element that is mounted on

use rum/defcc instead of rum/defc, you’ll get additional first argument which will be React component. Then just use .findDOMNode to get to the DOM:

(rum/defcc my-component [comp arg1 arg2]
  (let [node (.findDOMNode comp)]
    ...))

@gmp26
Copy link

gmp26 commented Nov 12, 2015

Does the solution above work? I'm seeing this on the original and a variant that matches what I understand from the React API for .findDOMNode:

(rum/defcc my-component [comp arg1 arg2]
  (let [node (.findDOMNode comp)]
    [:div]))
; "fails with: Uncaught TypeError: comp.findDOMNode is not a function"

(rum/defcc my-component [comp arg1 arg2]
  (let [node (.findDOMNode js/React comp)]
    [:div]))
;  "fails with: Invariant Violation: findComponentRoot(...): Unable to find element.  This probably means the DOM was unexpectedly mutated ..."

@tonsky
Copy link
Owner

tonsky commented Nov 12, 2015

It’s (js/React.findDOMNode comp), sorry about the mistake

@gmp26
Copy link

gmp26 commented Nov 13, 2015

Thanks - I'm probably missing something - but (js/React.findDOMNode comp) gives me the same error as (.findDOMNode js/React comp).

Could it be that .findDOMNode is being called before the element is created, so triggering an Invariant Violation?

@tonsky
Copy link
Owner

tonsky commented Nov 13, 2015

Yes, you should not probably call it during the initial render

On Fri, Nov 13, 2015 at 3:40 PM Mike Pearson notifications@github.com
wrote:

Thanks - I'm probably missing something - but (js/React.findDOMNode comp)
gives me the same error as `(.findDOMNode js/React comp).

Could it be that .findDOMNode is being called before the element is
created, so triggering an Invariant Violation?


Reply to this email directly or view it on GitHub
#48 (comment).

@gmp26
Copy link

gmp26 commented Nov 13, 2015

OK, thanks. Rum is really neat BTW :)

@tonsky tonsky closed this as completed Jun 19, 2016
@featheredtoast
Copy link

For the wayward traveler finding this issue now (react 15.1+) per this SO post it's now (js/ReactDOM.findDOMNode comp)

React.findDOMNode
has been deprecated, use

ReactDOM.findDOMNode
in React 15.1 and up

https://facebook.github.io/react/docs/react-dom.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants