GithubHelp home page GithubHelp logo

Comments (7)

vzaidman avatar vzaidman commented on May 22, 2024

what version of react do you use?

from why-did-you-render.

paramsinghvc avatar paramsinghvc commented on May 22, 2024

16.8.6.

from why-did-you-render.

vzaidman avatar vzaidman commented on May 22, 2024

how "TakeNotes " looks like?

from why-did-you-render.

paramsinghvc avatar paramsinghvc commented on May 22, 2024
import React, {
  useMemo,
  useState,
  useEffect,
  useRef,
  useCallback
} from "react";

import * as utils from "src/shared/utils";
import ChartData from "./data";
import useSlipper from "@dp-ui/utils/dist/useSlipper";
import useRedux from "@dp-ui/utils/dist/redux-hooks";
import { fetchHome } from "../Home/home.redux";
import { Layout, Container } from "./styles";
import safeGet from "@dp-ui/utils/dist/safeGet";
import { Icon } from "antd";

const TakeNotes = props => {
  const onSubmitHomeNavigator = useCallback((): void => {
    props.history.push("/");
  }, []);
  const { bigNumber, vCompare } = useMemo(
    () => utils.calculateData(ChartData.data),
    []
  );
  const [notes, setNotes] = useState("");
  const [submitFlag, setSubmitFlag] = useState(false);
  const notesRef = useRef<HTMLUListElement>(null);
  useSlipper(notesRef as React.MutableRefObject<HTMLUListElement>, {
    handleSelector: "slider"
  });
  const notesChangeHandler = text => {
    setNotes(text);
  };
  const prepareData = (mappedPropsData: any[]): any[] => {
    const data =
      mappedPropsData.filter(curr => {
        return curr.id === parseInt(props.match.params.notesID);
      })[0] || {};
    return safeGet(data, "notes", []);
  };

  const mappedProps = useRedux<any, any, any, {}>(s => s, { fetchHome });

  useEffect(() => {
    //action to load page data
    if (!mappedProps.pins.payload) mappedProps.fetchHome();
    safeGet(
      mappedProps,
      `mappedProps.pins.payload[${parseInt(props.match.params.notesID) ||
        0}].notes`,
      []
    );

    // eslint-disable-next-line no-console
    console.log("Mounted");
  }, []);
  return (
    <React.Fragment>
      <Layout className="layout">
        <Container>
          <div className="notesHeader">Take notes</div>
          <div className="navigationHome" onClick={onSubmitHomeNavigator}>
            DONE
          </div>
          <div className="notesArea" />
          <div className="discountedHeadersGroup">
            <div className="dailyTotalDiscountedOrders">
              DAILY - TOTAL DISCOUNTED ORDERS
            </div>
            <div className="daily">DAILY</div>
          </div>
          <div className="progressGroup">
            <div className="discountedOrderNumber">
              {Math.round((bigNumber / 1000) * 100) / 100}K
            </div>
            <div className="percentageGroup">
              <div
                className={
                  vCompare > 0 ? "chart-progress-up" : "chart-progress-down"
                }
              >
                {vCompare < 0 ? "▼" : "▲"}
              </div>
              <div
                className={
                  vCompare > 0 ? "wowPercentage-up" : "wowPercentage-down"
                }
              >
                {Math.round(vCompare * 100 * 100) / 100}% WOW
              </div>
            </div>
          </div>
          <div className="horzontalSeparator" />
          <div className="inputBoxNotes">
            <textarea
              className="inputAreaNotes"
              value={notes}
              onChange={evt => notesChangeHandler(evt.target.value)}
              maxLength={60}
              placeholder="write a note..."
              rows={6}
              cols={40}
              onFocus={() => setSubmitFlag(true)}
            />
            <div className="textLength">{notes.length}/60</div>
          </div>
          {submitFlag && (
            <div className="actionGroup">
              <div
                className="cancel"
                onClick={() => {
                  notesChangeHandler("");
                  setSubmitFlag(false);
                }}
              >
                <span className="cancelText">Cancel</span>
              </div>
              <div className="submit" onClick={() => null}>
                <span className="submitText">Submit</span>
              </div>
            </div>
          )}
          <div className="previousNotes">Previous notes</div>
          <div>
            <Icon type="close" />
          </div>
          >
          <ul className="notesList" ref={notesRef}>
            {mappedProps.pins.payload &&
              prepareData(mappedProps.pins.payload).map((curr, index) => {
                return (
                  <li className="noteRow" key={index} id={`${index}`}>
                    <div className="parallelRow">
                      <div className="row">
                        <div className="deleteRow">X</div>
                        <div className="noteData">
                          <span className="noteTitle">{curr.text}</span>
                          <span className="noteTimestamp">
                            {`${utils.dateUtility(curr.updatedAt).day} ${
                              utils.dateUtility(curr.updatedAt).month
                            } | 3.7K weekly`}
                          </span>
                        </div>
                        <div className="slider">E</div>
                      </div>
                      <div className="eachNoteSeparator" />
                    </div>
                  </li>
                );
              })}
          </ul>
        </Container>
      </Layout>
    </React.Fragment>
  );
};
TakeNotes.whyDidYouRender = true;
export default TakeNotes;

from why-did-you-render.

paramsinghvc avatar paramsinghvc commented on May 22, 2024

It's quite strange, why would React.useRef() return an empty string instead of a ref object?

from why-did-you-render.

vzaidman avatar vzaidman commented on May 22, 2024

Please provide a sandbox with a reproduction of this issue.
I couldn't figure out how could this happen.

from why-did-you-render.

vzaidman avatar vzaidman commented on May 22, 2024

This issue would be reopened when more information is provided.

from why-did-you-render.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.