<commit_before>import { h, Component } from 'preact';
import style from './style';

export default class Recipe extends Component {
  constructor() {
    super();

    this.handleClick = this.handleClick.bind(this);

    this.state = {
      brewCreated: false,
    };
  }

  handleClick(event) {
    const { id, createBrew } = this.props;

    createBrew(id).then(this.setState({ brewCreated: true }));

    event.preventDefault();
  }

  render() {
    const { id, recipes, user } = this.props;
    const { brewCreated } = this.state;

    const recipe = recipes.find((recipe) => recipe._id === id);

    // if no recipes its loading so show a placeholder
    if (!recipes.length) {
      return (
        <div>
          <div class={style.placeholder} />
          <div class={style.placeholder} />
        </div>
      );
    }<commit_msg>fix(state): reset state for recipe component when unmounting<commit_after>import { h, Component } from 'preact';
import style from './style';

export default class Recipe extends Component {
  constructor() {
    super();

    this.handleClick = this.handleClick.bind(this);

    this.state = {
      brewCreated: false,
    };
  }

  componentWillUnmount() {
    this.setState({ brewCreated: false });
  }

  handleClick(event) {
    const { id, createBrew } = this.props;

    createBrew(id).then(this.setState({ brewCreated: true }));

    event.preventDefault();
  }

  render() {
    const { id, recipes, user } = this.props;
    const { brewCreated } = this.state;

    const recipe = recipes.find((recipe) => recipe._id === id);

    // if no recipes its loading so show a placeholder
    if (!recipes.length) {
      return (
        <div>
          <div class={style.placeholder} />
          <div class={style.placeholder} />
        </div>
      );
    }
{'fraction_non_alphanumeric': 0.1404867256637168, 'fraction_numerical': 0.0, 'mean_word_length': 2.5680473372781063, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3927118', 'n_tokens_mistral': 546, 'n_tokens_neox': 534, 'n_words': 137}