0
我有一個反應組件,它顯示了一個消息:,呼叫作出反應組件顯示像一個警報功能
下面的代碼:
import React, { PropTypes } from 'react';
const Message = props => {
const { type, msg } = props;
if (type === 'success') {
return (<div>{msg}</div>);
} else {
return null;
}
};
Message.PropTypes = {
type: PropTypes.string.isRequired,
msg: PropTypes.string.isRequired,
};
export default Message;
//這一部分稱爲像這樣從指標。 js:
<Message type="success" msg="This is a Message" />
我的問題是...我怎樣才能調用組件,就像我會調用一個函數。
例如:
if (function is success then) {
//Show the Message Component
}
我怎樣才能做到這一點與反應是?
怎麼樣與一個onclick事件? – JakeBrown777
@ JakeBrown777你是什麼意思? –