score:0
there were two problems;
s => this.setstate(s)
in your pivottable's onchange property. this overrides root state with all the props of your pivottable. when your page initiated, container's (grid
) state only containsselectedoption:"region"
but after interacting with the pivottable, container has receives all the props of the pivottable. screenshot:{...this.state}
prop inpivottableui
component, passes all keys as props in container's state includingdata
.(as seen in the screenshot above). and this overridesdata
property,data={datadic[this.state.selectedoption]}
after this, changes toselectedoption
state does not re-renderpivottableui
solution
change
s => this.setstate(s)
withthis.setstate({ pivottableuiconfig: s });
define a
pivottableuiconfig
variable which does not include data property. (used es7 object rest operator to omit data property)// picking all the properties except "data" const { data, ...pivottableuiconfig } = this.state.pivottableuiconfig;
change
{...this.state}
with{...pivottableuiconfig}
score:0
encountered the same problem and found a simple fix. the problem is that data
prop always gets overwritten by {...state}
. hence we can assign data to state before passing it to pivottableui
. and the data
prop is no longer needed.
const state = {...this.state};
state['data'] = datadic[this.state.selectedoption];
return (
<pivottableui
onchange={s => this.setstate(s)}
{...state}
/>
)
score:0
you should add
renderers={{ ...tablerenderers, ...plotlyrenderers }}
{...state}
to your pivottableui
, see the full example:
import tablerenderers from 'react-pivottable/tablerenderers';
import pivottableui from 'react-pivottable/pivottableui';
import plot from 'react-plotly.js';
import createplotlyrenderers from 'react-pivottable/plotlyrenderers';
import 'react-pivottable/pivottable.css';
const plotlyrenderers = createplotlyrenderers(plot);
function dataexploration() {
const { dashboarddata: { data } } = useselector((state) => state.dashboarddata)
const expcomp = (props) => {
const [state, setstate] = usestate(props);
return (
<div classname="row">
<div classname="col-md-12">
{
<pivottableui
style={
{
width: "100%",
height: "100%"
}
}
onchange={(s) => setstate(s)}
renderers={{ ...tablerenderers, ...plotlyrenderers }}
{...state}
/>
}
</div>
</div>
)
}
return (
<expcomp data={data} />
)
}
from more details check the doc: https://github.com/plotly/react-pivottable
score:1
i found that if i delete the data property from s
<pivottableui
data = {[{}]}
onchange={ s =>{
delete s.data
this.setstate(s)
}}
{...this.state}
/>
this won't overwrite the data in the parent class and will be automatically rendered with updated data
Source: stackoverflow.com
Related Query
- How do I re render the entire React Pivot Table UI component when I change the selection in select tag?
- how to change the style of only one react component that is being render through .map() when the component is clicked
- How to pass the match when using render in Route component from react router (v4)
- How to change the state of the particular component when it is clicked, using useState in react js?
- React - How to update my component when there is a change on the server
- re render a react component only when the state change
- React - How to change the props of a child component when an event happens?
- How to make React page render only change component instead of the whole page?
- React - is the following true about how html tags' attribute values change when a component is reexecuted?
- How do I wrap a React component that returns multiple table rows and avoid the "<tr> cannot appear as a child of <div>" error?
- React - How to detect when all sub-components of a parent component are visible to the user?
- how to rerender a component when hash change and change the state
- ReactJS how to render a component only when scroll down and reach it on the page?
- Component not updating when I change the props that I pass to it in React
- How to notify parent component of property change when using react hooks?
- how and when to call a react component methods after state change from redux
- How to stop re render child component when any state changed in react js?
- Change the state when clicking outside a component in React
- React : How to stop re-rendering component or making an API calls on router change for the same route
- How to make MobX update the component when observable is not used in the render method?
- How can I cancel the next 'then' in a Promise when a React component is unmounted/reused?
- React - How do i force child components to re render when parent state component changes?
- React useEffect calls API too many time, How can I limit the API call to only once when my component renders?
- How to change the selected table row background color with React
- How to change the selected table row background using Material-UI on React
- React - How change state of single component when there are multiple instance of same component?
- How to make one table record editable on button click in React when the table record is mapped?
- React - How to change code written in the old way when using a new approach?
- How can I use useEffect in React to run some code only when the component first mounts, and some other code whenever an event occurs (repeatedly)?
- Why does the render function in react is called twice when using the component strategy?
More Query from same tag
- How to focus on html select on page load or button click in react js?
- CodeSandbox - PostCSS received undefined instead of CSS string
- Can I disable the Material-UI SpeedDial mouseover event
- TypeError: Cannot read property 'url' of undefined / React App crashing
- Webpack - Build css not applied
- Generics in React TSX Files
- Nested routes inside react component
- Tree data table with fixed (affix) parent rows
- onProgress with uploadData() method is giving progress update only once i.e. the final response
- React-Google-Maps: Marker resizes after zooming
- WP API and React rendering HTML, not text
- Webpack not detecing proxy for local development
- React Redux Persist is rehydrating, but no stored data is retrieved, instead, default
- React Ionic (v5): IonReactRouter & IonRouterOutlet Not Working as Expected
- Export two constants from one component to another
- Why is there a semi-colon in the object structure for expected props in this typescript react component?
- make dropdown menu visible using react
- Will await wait till the completion of function NOT returing a promise
- Flow - Cannot call `data.map` because property `map` is missing in `FetchData` [1]
- how to import reducer to store.js from createSlice @reduxjs/toolkit
- How to display objects without duplicate headers?
- How to return Objects with Object.keys Javascript
- React-Chart-JS2 labels inside Doughnut chart
- React useState. Why do the docs advise passing a function with the previous state when setting the state?
- Using Tag to pass a attribute inside NavLink reactstrap component
- useEffect not setting data to state in functional component
- Getting error while updating state in reactjs
- Reordering list items by onclick with ReactJs
- react counter for each item of list
- Routing not working with deployed create-react-app on github pages with react-router v6