⚠️ This lesson is retired and might contain outdated information.

transferPropsTo [DEPRECATED]

Joe Maddalone
InstructorJoe Maddalone
Share this video with your friends

Social Share Links

Send Tweet
Published 10 years ago
Updated 6 years ago

THIS METHOD HAS BEEN DEPRECATED the transferPropsTo method lets you easily push properties into your components to easily customize attributes.

Joe Maddalone: We've got this little wrapper around a bootstrap button. It returns a button primary. It gets our inner content, which is awesome.

It can have these nested components, which is great, but it sucks because I can't pass it anything else. I can't make it a different type of button. I really don't want to go and recreate the anchor tag as a component to pass in a bunch of properties, state, and all sorts of stuff.

The way that we can solve this is with this.transferPropsTo. We just wrap a return in that. What ends up happening is any properties that we pass to B button get passed to the next component, which, in our case, is an anchor tag.

We definitely want it to be a button. Let's say we're going to be responsible for passing in the type of button. I'm going to pass in a class name here.

Transfer Properties To is smart enough to know that when we pass in an additional class name, when it already has a class name, it'll just append that. It'll just add it to it.

We're just going to say, "Button and this next one and next one." Here, we'll do "Success." Here, we'll do "Danger." Load that up in the browser. Whoops.

You know what? Now that we've got multiple components, we need to have a parent. There we go. Load that up. Nope. That did not work. What'd I do wrong? Let's look at the console here. Unexpected token.

Let's pull this out a little bit. You know what? I didn't close that div. Let's load this up. There we go. We've got our three buttons with their three different classes.

That's pretty cool, but now we're stuck with this B heart thing. It just returns the heart icon. That sucks. Let's make this a little more reusable. We'll use this.transferPropsTo. Wrap a return in that.

We're going to change this to B icon. We'll be responsible for telling it which type of icon we want. Let's change all these to P icon. We'll say, "Class name equals..."

It's a little messy. That's fine. Let's drop this on the next line, this on the next line, and this on the next line. Here, it's a heart.

You know what? I don't know these that well. It's really good that I have it opened up in another window. I'll just pick some random ones. Load that back up. Now, we've got our different icons. That's awesome.

The other thing we can do, we can pass it just arbitrary stuff. Let's give each one of them an href. Href equals...This is all going to start pushing way down the screen. Alert hello.

Now, all of them should have an href. We've passed that href to B button. It's transferring that property to this anchor tag. When we click on it, we should get "Hello." Hello. Awesome.

There you go. That's a quick look at transferPropsTo.

Nicolas
Nicolas
~ 10 years ago

So in this exemple, I guess the href is also transferred to the glyficon, is it ?

Joe Maddalone
Joe Maddaloneinstructor
~ 10 years ago

No. The props are only transferred to the first component.

Example: this.transferPropsTo(<span><b><i>xxx</i></b></span>)

Here only the span component would get the props.

This also translates to: this.transferPropsTo(React.DOM.span(null, React.DOM.b(null, React.DOM.i(null, "xxx"))))

So transferPropsTo is only concerned about the first argument, in this case <span> or React.DOM.span, knowing nothing about what might be nested further.

Wei-Ting
Wei-Ting
~ 9 years ago

Any update for this? transferPropsTo is deprecated. Thanks

David
David
~ 9 years ago

Would be great if this video could be removed/updated. Reading the documentation on https://gist.github.com/sebmarkbage/a6e220b7097eb3c79ab7 doesn't make much sense on getting this particular tutorial to work. I'm unable to understand how to append classes (transfer the props from one component to another).

I just spent an hour trying to get this particular tutorial to work referencing the gist and have no luck.

The video need not be updated, but a comment from the author with a code snippet would do enough, then we could simply draw the connection along with the official docs.

Joel Hooks
Joel Hooks
~ 9 years ago

Joe commented above (still valid). I've added some additional signage around the lesson to indicated that this has ben DEPRECATED

It doesn't work. Move along :>

Lakshmi Narayana Sastry Marthi
Lakshmi Narayana Sastry Marthi
~ 9 years ago

hi, what is the text editor used in these videos?

Markdown supported.
Become a member to join the discussionEnroll Today