0

这是我尝试仅在用户名与用户名匹配时才呈现的 Moralis 代码:

function Redpit() {
    const { authenticate, isAuthenticated, user } = useMoralis();
    const [isActivated, setisActivated] = useState(false);
    const { Moralis, isInitialized } = useMoralis();
    const { data, error, isLoading } = useMoralisQuery("Posts");

    const results = JSON.stringify(data, null, 2)
    const finalResult = JSON.parse(results)

    const createPost = () => {
        setisActivated(true);
    }

    useEffect(async () => {
        const query = await new Moralis.Query("Posts");
        const posts = query.find();
    }, [])

return(

                                <div class="pit-post">

                                    <figure>

                                        <span><i class="fa fa-bolt"></i></span>

                                        <i class="fa fa-image"></i>

                                    </figure>

                                        {finalResult.map((result) => {

                                            {user.get("username") === result.author.username ? <Userpost /> : void(0)}                                  
                                        })}

)
}

这是我要渲染的代码:

import { useMoralis, useMoralisQuery } from "react-moralis";

function Userpost() {

    const { data, error, isLoading } = useMoralisQuery("Posts");

    const results = JSON.stringify(data, null, 2)

    const finalResult = JSON.parse(results)

    return (

        <div>

            {finalResult.map((result) => {

                                            return <div class="central-meta item">

                                            <div class="pit-post">

                                                <figure>

                                                    <img src="images/resources/red-post2.jpg" alt="" />

                                                    <i class="fa fa-video"></i>

                                                </figure>

                                                <div class="pit-post-deta">

                                                    <h4><a href="social-post-detail.html" title="">{result.title}</a></h4>
</div>
                                        })}

        </div>

    )

}

export default Userpost

我只在用户与当前用户匹配时才尝试渲染组件,但它没有按预期渲染,因为它什么也不渲染。代码中没有错误,它只是什么都不渲染。

4

0 回答 0