这就是我的组件的样子
import React from "react";
import Radium from "radium";
import StyleRoot from "radium";
var styles = {
base: {
background: 'blue',
border: 0,
borderRadius: 4,
color: 'white',
padding: '1.5em',
width: '15%',
'@media (min-width: 320px)': {
width: '100%'
},
':hover': {
backgroundColor: 'red'
},
':focus': {
backgroundColor: 'green'
},
':active': {
backgroundColor: 'yellow'
},
},
block: {
display: 'block',
':hover': {
boxShadow: '0 3px 0 rgba(0,0,0,0.2)'
}
},
};
class LoginPage extends React.Component {
render() {
return (
<StyleRoot>
<button style={[
styles.base,
this.props.block && styles.block
]}>
{this.props.children}
</button>
</StyleRoot>
);
}
}
// https://github.com/FormidableLabs/radium/issues/816
// https://github.com/storybooks/storybook/issues/455
export default Radium(LoginPage);
我的
package.json
条目看起来像"radium": "^0.19.1",
我什至尝试了以下导入
import {StyleRoot} from "radium";
但是错误仍然相同。整个堆栈跟踪看起来像
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
getClosestInstanceFromNode @ ReactDOMComponentTree.js:113
findParent @ ReactEventListener.js:38
handleTopLevelImpl @ ReactEventListener.js:67
perform @ Transaction.js:143
batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates @ ReactUpdates.js:97
dispatchEvent @ ReactEventListener.js:147
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$l955y3wpg6n' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
在执行以下步骤时我错过了什么?
最佳答案
它说“包装您的应用程序”,因为StyleRoot
在调用Radium
函数之前必须存在:
let Wrapper = ({ children }) => <StyleRoot>{children}</StyleRoot>
ReactDOM.render(
<Wrapper><LoginPage /></Wrapper>,
el,
)
您可能已经具有不是LoginPage的根级组件,因此可以使用它而不是制作新的包装器组件。
同样,
import {StyleRoot} from 'radium';
是正确的语法。如果要同时导入Radium
和Styleroot
,则如下所示:import Radium, {StyleRoot} from 'radium';
关于javascript - 使用MediaQuery时,镭 react 报告“请将您的应用程序包装在StyleRoot组件中”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45221532/