- I am trying to change all the components into es6
- I did for two but not sure how to do for the third one.
- can you tell me how to change it?
providing my code below.
export default class FirstTimeTab extends React.Component{ getInitialState(){ return { 'panes' : [ <div className="sports-tab-content"> <p className="sports-large-text ft-day1 ft-day2">
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
this
is unavailable in that method.. when you callthis.changeContent
on line 60 change it tothis.changeContent.bind(this)
. That will bind your component instance to the method.you can also do this in a constructor if you want to by adding:
this.changeContent = this.changeContent.bind(this)
inside the constructor belowsuper(props)
, then you can use the method as you have itCan read more about
bind
here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bindYou had multiple small errors, one after another, that needed to be fixed. I highly recommend you make smaller changes so you can track more easily what goes wrong during development.
Updated Fiddle
First, remove
export default
fromexport default class FirstTimeTab extends React.Component
. This isn't necessary when working in a single-file Fiddle like we are doing here.That leaves you with
Running from there will give you the console error that
App
is undefined:Which is entirely true, since you changed
App
toFirstTimeTab
. After changing this to use<FirstTimeTab />
, you'll get yet another helpful console error that:This message is pretty clear: you can't use
getInitialState
with theclass
syntax. Instead, change to the more clear method of setting the initialstate
property in theconstructor
:Finally, you still won't see anything until you properly display your content. You were setting the content in the
content
attribute of eachPane
, when it seems like the rest of your code expects it to be passed aschildren
(which is the more correct way in React):Edit for followup:
You've been specifying required props with these bits of code:
The above states, for examples, that you require a
label
andchildren
for thePane
.If your error is Required prop
content
was not specified inPane
, this means somewhere in your code you are requiringcontent
as an attribute. In my answer above, I recommended you switch from passing your content incontent
to passing it through thechildren
property. If you followed that advice, just remove the line that causes this requirement. It should look like the piece of code I added above, though I saw no evidence of that in your original Fiddles. Maybe it was something you added later.