Skip to content

Allow valid react elements to be used in data manipulator #41

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

Open
dextermb opened this issue Dec 10, 2018 · 3 comments
Open

Allow valid react elements to be used in data manipulator #41

dextermb opened this issue Dec 10, 2018 · 3 comments

Comments

@dextermb
Copy link
Contributor

I want to add a symbol (such as an up/downward facing arrow) within a single column. I'd like to be able to do this within the dataItemManipulator function as I am only changing a single column.

If we want to keep dataItemManipulator clear of elements, then we should look into implementing a low level cellRenderer on DataRow.

Currently the object/array check in renderCell causes a circular JSON.stringify error when attempting to pass a React element into it (as a React element is an object, verified by $$symbol).

Here's the current expression:

if (typeof value === 'object' || typeof value === 'array') {
    value = JSON.stringify(value);
}

Perhaps this could be:

if (!React.isValidElement(value)) {
    value = JSON.stringify(value);
}

Or:

import Util from '@ninetynine/util';

// ...

if (Util.isObject(value) || Util.isArray(value)) {
    value = JSON.stringify(value);
}

It's worth noting that currently null gets stringified as in JavaScript null is an object.

Thoughts?

cc @NilesB @DivineOmega @wheatleyjj

@AlexCatch
Copy link

This would probably make more sense being a seperate prop, dataItemManipulator should just be a function for manipulating data & not rendering components IMO.

@DivineOmega
Copy link
Contributor

I think the isValidElement makes sense in this situation.

@dextermb
Copy link
Contributor Author

I think the isValidElement makes sense in this situation.

Indeed as isValidElement would return true for anything renderable (PropTypes.node).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants