0

I'm making my first React-Redux project.

I'd like to change the structure below simply.

const PresentationalComponent = ({
    params,
    query
}) => {
    if (query.title === undefined) {
        return (
            <div>
                <article>
                    <h2>{params.title}</h2>
                    <hr></hr>
                    <p>{params.content}</p>
                </article>
            </div>
        ); 
    } else {
        return (
            <div>
                <div>
                <article>
                    <h2>{query.title}</h2>
                    <hr></hr>
                    <p>{query.content}</p>
                </article>
            </div>
            </div>
        ); 
    }
};

export default HomeDetail;

This is what I've tried. But it occurs error.

<article>
    <h2>{query.title === undefined ? {item.title} : {query.title}}</h2>

Can we make it simple?

1 Answer 1

2
const PresentationalComponent = ({ params, query }) => (
    <div>
        <article>
            <h2>{query.title ? query.title : params.title}</h2>
            <hr></hr>
            <p>{query.title ? query.content : params.content}</p>
        </article>
    </div>
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.