Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_addToast() {
const { text, action } = this.state;
const toasts = this.state.toasts.slice();
toasts.push({ text, action });
const words = text.split(' ').length;
const autohideTimeout = Math.max(
Snackbar.defaultProps.autohideTimeout,
(words / AVERAGE_WPS) * 1000
);
this.setState({ toasts, autohideTimeout });
}
import React, { PureComponent } from 'react';
import Button from 'react-md/lib/Buttons/Button';
import Snackbar from 'react-md/lib/Snackbars';
import CardActions from 'react-md/lib/Cards/CardActions';
import TextField from 'react-md/lib/TextFields';
import SelectionControl from 'react-md/lib/SelectionControls/SelectionControl';
import './_interactive.scss';
export default class Interactive extends PureComponent {
state = {
toasts: [],
text: 'Hello, World!',
action: '',
autohide: true,
autohideTimeout: Snackbar.defaultProps.autohideTimeout,
};
handleSubmit = (e) => {
e.preventDefault();
const { text, action } = this.state;
const toasts = this.state.toasts.slice();
toasts.push({ text, action });
this.setState({ toasts });
};
handleReset = () => {
this.setState({
text: '',
action: '',
autohide: true,
handleReset = () => {
this.setState({
text: '',
action: '',
autohide: true,
autohideTimeout: Snackbar.defaultProps.autohideTimeout,
toasts: [],
});
};
Toast
<button type="reset" id="interactive-snackbar-reset">
Reset
</button>
);
}
}