Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. #2656

Closed
MyStarrySpace opened this issue Sep 29, 2023 · 6 comments · Fixed by #2679
Assignees
Labels
Note: Good first issue 🤩 Good issue for new contributors Type: TypeScript Issues related to typescript or type definitions

Comments

@MyStarrySpace
Copy link

MyStarrySpace commented Sep 29, 2023

Describe the bug
When using React with Next.JS, I am getting the warning: "Warning: (component name): Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead." This occurs for many different components, such as FlyOut, Curve, VictoryLabel, and many others.

Victory version
[email protected]
Which npm version are you using? 9.8.1

Code Sandbox link
Just make the following page in Next.js:

'use client'
import React, { ReactNode, useState, useEffect, useRef } from 'react';
import { VictoryLine, VictoryChart, VictoryTooltip, VictoryVoronoiContainer, VictoryAxis } from 'victory';

function generateSampleData(minAge = 16, maxAge = 100, numSamples = 100) {
    const sampleData = [];
    for (let i = 0; i < numSamples; i++) {
        const age = Math.floor(Math.random() * (maxAge - minAge + 1)) + minAge;
        const completes = Math.floor(Math.random() * 101);  // Replace with an appropriate range for your use case
        sampleData.push({ age, completes });
    }
    return sampleData;
}

export const PlotAgeCompletes = () => {

    const data = generateSampleData();
    const [isClient, setIsClient] = useState(false);

    useEffect(() => {
        setIsClient(true); // doing this to prevent hydration error
    }, [])

    return (
        <>
            {isClient ? (
                <VictoryChart
                    containerComponent={
                        <VictoryVoronoiContainer
                            voronoiDimension="x"
                            labels={({ datum }) => `Age: ${datum.age}, Completes: ${datum.completes}`}
                            labelComponent={
                                <VictoryTooltip cornerRadius={0} flyoutStyle={{ fill: "white" }} />
                            }
                        />
                    }
                >
                    <VictoryAxis label="Age" />
                    <VictoryAxis dependentAxis label="Completes" />
                    <VictoryLine
                        data={data}
                        x="age"
                        y="completes"
                    />
                </VictoryChart>
            ) : (
                <div></div>
            )}
        </>
    );
};

export default PlotAgeCompletes;

To Reproduce
Steps to reproduce the behavior:

  1. Create a Next.JS project
  2. Create a graph with Victory
  3. Get the warning in the console

Expected behavior
No warning appears

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 11 Pro, 64-bit operating system, x64-based processor
  • Browser: Google Chrome
  • Version: 117.0.5938.92 (Official Build) (64-bit)
@Yomyer
Copy link

Yomyer commented Oct 26, 2023

I have the same problem using NextJS 13 with AppRouter.

@danteyc
Copy link

danteyc commented Nov 2, 2023

Any update?

@Zhumatic
Copy link

Zhumatic commented Nov 3, 2023

same problem here, but the chart is rendering correctly.

@carbonrobot carbonrobot added Note: Good first issue 🤩 Good issue for new contributors Type: TypeScript Issues related to typescript or type definitions labels Nov 17, 2023
@acharyakavita acharyakavita self-assigned this Nov 20, 2023
@Renatofujimoto
Copy link

i have the same issue in the next13, any news?

@carbonrobot
Copy link
Contributor

Just an update on this one. We are working on a solution to removing defaultProps from all components and will release it in multiple minor-point releases.

Internally, Victory uses defaultProps in unique ways to pass values to components that are linked/chained together in a container, so some of the code is difficult to untangle.

Roughly, I will release it with the following plan, over the next couple weeks (depending on holidays)

  1. Remove default props from React functional components PR converted all functional components to use default parameters instead of defaultProps #2679
  2. Remove default props from Core React Class components
  3. Remove default props from remaining components

@carbonrobot
Copy link
Contributor

Released in https://github.com/FormidableLabs/victory/releases/tag/v36.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Note: Good first issue 🤩 Good issue for new contributors Type: TypeScript Issues related to typescript or type definitions
Projects
None yet
7 participants