私は自分のウェブサイト用のnotiferコンポーネントをビルドしています。基本的には、1つのヒットは「追加」と言い、アイテムはウェブサイトの上部に「追加」されています。緑色のバーが表示され、「正常に作成されました」と表示されます。Reactjのタイムアウトは?
1秒後に消えます。私はこれを行うための最善の方法は何でしょうか?それはどこかにjavascriptタイマーを持っているのですか?
import React from 'react';
import 'materialize-css/sass/materialize.scss';
import 'font-awesome/scss/font-awesome.scss';
import 'materialize-css/js/materialize.js';
import classNames from 'classnames/index.js';
export default class Notifer extends React.Component {
render() {
var notifcationClasses = classNames({
'notifcation-success': this.props.notiferReducer.success,
'notifcation-error': this.props.notiferReducer.error,
'hide': !(this.props.notiferReducer.success || this.props.notiferReducer.error)
});
return (
<div id="notifcation" className={notifcationClasses}>
Sucessfully created
</div>
);
}
}
アクション
import {actions} from './Actions.js';
export function setNotifer(success) {
return function (dispatch) {
dispatch({ type: actions.SET_NOTIFIER, payload: success });
};
}
リデューサー
import { actions } from '../actions/Actions';
export default function NotiferReducer(state = {
success: false,
error: false
}, action) {
switch (action.type) {
case actions.SET_NOTIFIER: {
return {
success: action.payload,
error: !action.payload
};
}
}
return state;
}
通常、私はうなり声のようなものを使用しますが、私は(まあ、私はいくつかを見ましたreactjsために何も表示されませんでしたが、それらのどれもに見えました非常に人気があります)
たsetTimeout(関数( ){alert( "Hello");}、3000);あなたは最善の方法を尋ねているので...私はダイアログボックスにOKボタンを置いています。特に、ユーザがそれを読んで理解するのに十分な時間があることを確認するためのエラーダイアログ。 – Sam
アクションクリエーターにタイムアウトを設定して、ビューを閉じる別のアクションをトリガーします。 – riscarrott
@riscarrottあなたはこれの例の多くを置くことができますか? 「追加」アクションまたは「ノーティファイヤー」アクションについて、どのアクションを話していますか? – chobo2