admin管理员组文章数量:1026088
I'm using the Drop javascript library, and I get this error:
Drop Error: Content function should return a string or HTMLElement.
I'm using React to handle a click, and then open the Drop popup.
popupContent: function() {
return (
<div>
<p>Test.</p>
</div>
)
},
initDrop: function() {
var self = this;
var drop = new Drop({
target: self.refs.xxx,
openOn: 'click',
content: function() {
self.popupContent();
}
});
},
How can I make the popupContent
function return as a string?
I'm using the Drop javascript library, and I get this error:
Drop Error: Content function should return a string or HTMLElement.
I'm using React to handle a click, and then open the Drop popup.
popupContent: function() {
return (
<div>
<p>Test.</p>
</div>
)
},
initDrop: function() {
var self = this;
var drop = new Drop({
target: self.refs.xxx,
openOn: 'click',
content: function() {
self.popupContent();
}
});
},
How can I make the popupContent
function return as a string?
1 Answer
Reset to default 1You should return String
from popupContent
because now popupContent
returns JSX
but JSX
is not a String
popupContent: function() {
return (
'<div>' +
'<p>Test.</p>' +
'</div>'
)
},
if you use ES2015 you can use Template literals
popupContent: function() {
return (
`<div>
<p>Test.</p>
</div>`
)
},
also there is package jsx-to-string
(note - you should install it)
popupContent: function() {
return jsxToString(
<div>
<p>Test.</p>
</div>
)
},
Example
I'm using the Drop javascript library, and I get this error:
Drop Error: Content function should return a string or HTMLElement.
I'm using React to handle a click, and then open the Drop popup.
popupContent: function() {
return (
<div>
<p>Test.</p>
</div>
)
},
initDrop: function() {
var self = this;
var drop = new Drop({
target: self.refs.xxx,
openOn: 'click',
content: function() {
self.popupContent();
}
});
},
How can I make the popupContent
function return as a string?
I'm using the Drop javascript library, and I get this error:
Drop Error: Content function should return a string or HTMLElement.
I'm using React to handle a click, and then open the Drop popup.
popupContent: function() {
return (
<div>
<p>Test.</p>
</div>
)
},
initDrop: function() {
var self = this;
var drop = new Drop({
target: self.refs.xxx,
openOn: 'click',
content: function() {
self.popupContent();
}
});
},
How can I make the popupContent
function return as a string?
1 Answer
Reset to default 1You should return String
from popupContent
because now popupContent
returns JSX
but JSX
is not a String
popupContent: function() {
return (
'<div>' +
'<p>Test.</p>' +
'</div>'
)
},
if you use ES2015 you can use Template literals
popupContent: function() {
return (
`<div>
<p>Test.</p>
</div>`
)
},
also there is package jsx-to-string
(note - you should install it)
popupContent: function() {
return jsxToString(
<div>
<p>Test.</p>
</div>
)
},
Example
本文标签: javascriptReturn a React39s method 39return39 as a stringStack Overflow
版权声明:本文标题:javascript - Return a React's method 'return' as a string - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745632009a2160222.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论