php - 将 nextjs 应用程序转换为 wordpress 简码
问题描述
我需要一些帮助。
我真的很喜欢 WordPress 作为 cms,但我不是 PHP 的粉丝。我偶然发现了 Next.js,并在那里迈出了第一步,这对我来说很棒。我只想将 WordPress 与 Divi 一起用于我的前端,并使用 next.js 构建组件和功能以摆脱 PHP。
我在 BSC 上创建了一个代币,我想为它创建一个空投系统。
现在我的问题是:如何将我的 Next.js 组件放入 WordPress 短代码中?
示例组件:index.js
import { useState, useEffect } from 'react';
import Web3 from 'web3';
import getBlockchain from './ethereum.js';
export default function Home() {
const [loading, setLoading] = useState(true);
const [loadingMessage, setLoadingMessage] = useState('Loading...');
const [claimMessage, setClaimMessage] = useState({
payload: undefined,
type: undefined
});
const [airdrop, setAirdrop] = useState(undefined);
const [accounts, setAccounts] = useState(undefined);
useEffect(() => {
const init = async () => {
try {
const { airdrop, accounts } = await getBlockchain();
setAirdrop(airdrop);
setAccounts(accounts);
setLoading(false);
} catch(e) {
setLoadingMessage(e);
}
};
init();
}, []);
const claimTokens = async e => {
e.preventDefault();
const address = accounts[0];
const totalAllocation = 100000000000000000000000;
try{
setClaimMessage({
type: 'primary',
payload: `Claiming token from Airdrop contract...\nAddress: ${address}\nTotal Amount:
${Web3.utils.fromWei(totalAllocation.toString())} MadDoge`
});
const receipt = await airdrop
.methods
.claimTokens(
address,
totalAllocation.toString()
)
.send({from: address});
setClaimMessage({
type: 'primary',
payload: `Airdrop success!\nTokens successfully in tx ${receipt.transactionHash} \nAddress: ${address}\nTotal Amount: ${Web3.utils.fromWei(totalAllocation.toString())} MadDoge`
});
} catch(e) {
setClaimMessage({
type: 'danger',
payload: `Airdrop had been claimd !!\nAddress:- ${address}`
});
}
};
return (
<div className='container'>
{loading ? (
<div className='row mt-4'>
<div className='col-sm-12'>
<div className="jumbotron">
<h3 className='text-center'>{loadingMessage}</h3>
</div>
</div>
</div>
) : null}
{loading ? null : (
<div className='row mt-4'>
<div className='col-sm-12'>
<div className="jumbotron">
<form className="form-inline" onSubmit={e => claimTokens(e)}>
<button
type="submit"
className="btn btn-primary mb-2 col-sm-12"
>
Claim airdrop
</button>
</form>
<div>
{typeof claimMessage.payload !== 'undefined' ? (
<div className={`alert alert-${claimMessage.type}`} role="alert">
<span style={{ whiteSpace: 'pre' }}>
{claimMessage.payload}
</span>
</div>
) : ''}
</div>
</div>
</div>
</div>
)}
</div>
);
解决方案
推荐阅读
- javascript - 搜索时不同的选择下拉菜单应具有相同的下拉选项值
- c# - 当用户在 textbox1 和 textbox2 中键入无效字符时,会出现“无效字符消息”并且 textbox1 的文本变为红色
- arrays - 打印二维数组:警告:数组初始值设定项中的多余元素
- linux - 无法完成与 2404:6800:4005:807::200e:80 的 SOCKS5 连接
- python - 如果你做太多'layers.MaxPooling2D()'会发生什么
- azure - 如何在 power shell 中使用 RM 模块获取 Azure App 配置访问密钥
- sails.js - 如何在 Sails.js 中将我们自己的自定义 JSON 消息添加到 Blueprint API?
- python - 结合CNN和双向LSTM
- r - Importing a csv file using fread loses factor order
- regex - Ansible 替换大配置文件中的值